比较版本号(istringstream)

题目:https://leetcode-cn.com/problems/compare-version-numbers/
代码:https://leetcode-cn.com/problems/compare-version-numbers/solution/istringstreamde-shi-yong-by-victoriacck/

class Solution {
     
public:
    int compareVersion(string version1, string version2) {
     
        char c;
        int v1,v2;
        istringstream its1(version1);
        istringstream its2(version2);
        
        while(bool(its1>>v1) + bool(its2>>v2)){
     //‘+’可以用'|'代替
            if(v1>v2) return 1;
            if(v1<v2) return -1;
            
            v1=0;
            v2=0;
            its1>>c;
            its2>>c;
            
        }
        
        return 0;
    }
};

你可能感兴趣的:(leetcode)