高效提取字符串中数字,以空格分割

class Solution {
public:
    bool areNumbersAscending(string s) {
        istringstream ss(s);
        int pre=-1;
        string res;
        while(ss>>res){
            if(isdigit(res[0])){
                int cur=stoi(res);
                if(cur<=pre) return false;
                pre=cur;
            }
        }
        return true;
    }
};

Li.2042

你可能感兴趣的:(leetcode,动态规划,贪心算法)