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

#include <leetcode.h>

静态 Public 成员函数

static bool canTransform (const string &start, const string &end)
 

详细描述

在文件 leetcode.h1086 行定义.

成员函数说明

◆ canTransform()

bool leetcode::swap_adjacent_in_lr_string::Solution::canTransform ( const string &  start,
const string &  end 
)
static

在文件 leetcode.cpp2747 行定义.

2747 {
2748 auto oss_start = ostringstream();
2749 auto oss_end = ostringstream();
2750 auto i_start = vector<int>();
2751 auto i_end = vector<int>();
2752 for(int i = 0; i < start.size(); i++) {
2753 char ch = start[i];
2754 if(ch == 'R' || ch == 'L') {
2755 oss_start << ch;
2756 i_start.push_back(i);
2757 }
2758 }
2759 for(int i = 0; i < end.size(); i++) {
2760 char ch = end[i];
2761 if(ch == 'R' || ch == 'L') {
2762 oss_end << ch;
2763 i_end.push_back(i);
2764 }
2765 }
2766 string str_start = oss_start.str();
2767 string str_end = oss_end.str();
2768 if(str_start != str_end) {
2769 return false;
2770 }
2771 for(int i = 0; i < i_start.size(); i++) {
2772 if(str_start[i] == 'R') {
2773 if(i_start[i] > i_end[i]) {
2774 return false;
2775 }
2776 } else {
2777 //L
2778 if(i_start[i] < i_end[i]) {
2779 return false;
2780 }
2781 }
2782 }
2783 return true;
2784 }

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


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