Both notes:
1. I dont know whether C + + have a good split function for STL as the JAVA. Need to figure it out.
2. At the beginning, I tried to set tmp1 = TMP2 = Int_min. But one of the test case does isn't work "1.0" and "1". So those, does not need to set is int_min or Int_max every time. It should is 0 at the this time.
1 classSolution {2 Public:3vector<string> Splits (strings) {4vector<string>result;5 intLen =s.size ();6 for(inti = len-1; I >=0; i--) {7 if(S[i] = ='.') {8Len =i;9}Else if(i = =0|| s[i-1] =='.') {TenResult.push_back (S.substr (i, Len-i)); One } A } - returnresult; - } the intCompareversion (stringVersion1,stringVersion2) { - if(version1.size () = =0&& version2.size () = =0)return 0; - if(version1.size () = =0)return-1; - if(version2.size () = =0)return 1; +vector<string> List1 =splits (version1); -vector<string> List2 =splits (version2); + intL1 = List1.size ()-1, L2 = List2.size ()-1; A while(L1 >=0|| L2 >=0) { at intTMP1 =0, TMP2 =0; - if(L1 >=0) { -TMP1 = Stoi (list1[l1--]); - } - if(L2 >=0) { -TMP2 = Stoi (list2[l2--]); in } - if(Tmp1 > TMP2)return 1; to Else if(Tmp1 < TMP2)return-1; + } - return 0; the } *};
Leetcode–refresh–compare Version Numbers