버전 비교 (istringstream)

3336 단어 leetcode
제목: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;
    }
};

좋은 웹페이지 즐겨찾기