Leetcode–refresh–compare Version Numbers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.