problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::number_of_ways_to_divide_a_long_corridor::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static int numberOfWays (string corridor)
 

详细描述

在文件 leetcode.h630 行定义.

成员函数说明

◆ numberOfWays()

int leetcode::number_of_ways_to_divide_a_long_corridor::Solution::numberOfWays ( string  corridor)
static

在文件 leetcode.cpp1388 行定义.

1388 {
1389 unsigned int s_count = 0;
1390 auto p = vector<unsigned int>();
1391 for(const char ch: corridor) {
1392 if(ch == 'S') {
1393 s_count++;
1394 }
1395 }
1396 if(s_count == 0 || s_count % 2 != 0) {
1397 return 0;
1398 }
1399 if(s_count == 2) {
1400 return 1;
1401 }
1402 unsigned int start = 0;
1403 unsigned int end = corridor.length() - 1;
1404 for(; start < end; start++) {
1405 if(corridor[start] == 'S') {
1406 break;
1407 }
1408 }
1409 for(; end > start; end--) {
1410 if(corridor[end] == 'S') {
1411 break;
1412 }
1413 }
1414 s_count = 1;
1415 unsigned int p_count = 0;
1416 bool flag = false;//是否在边界
1417 for(unsigned int i = start + 1; i <= end; i++) {
1418 if(corridor[i] == 'S') {
1419 s_count++;
1420 } else {
1421 if(s_count == 0) {
1422 p_count++;
1423 }
1424 }
1425 s_count %= 2;
1426 if(s_count == 0) {
1427 flag = true;
1428 } else if(s_count == 1) {
1429 if(flag) {
1430 p.push_back(p_count + 1);
1431 p_count = 0;
1432 }
1433 flag = false;
1434 }
1435 }
1436 unsigned long long ans = 1;
1437 for(const auto i: p) {
1438 ans *= i;
1439 ans %= 1000000007;
1440 }
1441 return ans;
1442 }

被这些函数引用 leetcode::number_of_ways_to_divide_a_long_corridor::TEST().


该类的文档由以下文件生成: