2194. Cells in a Range on an Excel Sheet

problem

solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution {
public:
vector<string> cellsInRange(string s) {
char a = s[0]+1, b = s[3];
vector<string> ret;
for(char c = s[0] ;c<=s[3] ; ++c){
for(int i=int(s[1]);i<=int(s[4]) ; ++i){
string temp ;
temp+=c;
temp+= char(i);
ret.push_back(temp);

}
}
return ret;
}
};

analysis

  • time complexity O(nm)
  • space complexity O(1)