leetcode 6016 Excel 表中某个范围内的单元格
思路
- 取 string s 的字母和数字部分
- 套两层 for 循环,外部字母(列),内部数字(行)
- 遍历到后面的字母或者数字截至
题解
class Solution {
public:
vector<string> cellsInRange(string s) {
vector<string> ans;
// 行列起始和边界
char a = s[0], b = s[3];
char c = s[1], d = s[4];
// 存储数字起点
char tmp = c;
while(a <= b) {
string path = "";
path += a;
while(c <= d) {
string path1 = path;
path1 += c;
ans.push_back(path1);
c = c + 1;
}
c = tmp;
a = a + 1;
}
return ans;
}
};