개발 로그/알고리즘
2042. Check if Numbers Are Ascending in a Sentence.cpp
k._.
2021. 10. 18. 10:29
🔑 isdigit으로 숫자만 추출한 다음, 대소 비교를 한다.
class Solution {
public:
bool areNumbersAscending(string s) {
bool res = true;
string tmp = "";
int min = -1;
for(int i =0; i<s.size(); i++){
while(isdigit(s[i])){
tmp += s[i];
i++;
}
if(tmp!=""){
int tmpInt = stoi(tmp);
if(tmpInt > min){
min = tmpInt;
tmp = "";
}else{
return false;
}
}
}
return res;
}
};