165. Compare Version Numbers
Compare numbers version1 and version2.
If version1 > version2 return 1, if version1 < version2 return-1, otherwise ret Urn 0.
Assume that the version strings is non-empty and contain only digits and the.
The.
For instance,2.5
Here are an example of version numbers ordering:
0.1 < 1.1 < 1.2 < 13.37
Ideas:
1. Divide the two versions of the string into a vector.
2. Compare the size of the elements in the 2 vectors.
Note: 1 = = 1.0.0
Class solution {public:    vector<int> stringsplit (String s,  const char * split)     {         vector<int> result;        const int slen  = s.length ();        char *cs = new  char[slen + 1];        strcpy (Cs, s.data ());         char *p;        char  * end;        p = strtok (Cs, split);         while  (P)         {             printf ("%s\n",  p);         &nbsP;   string tmp (P);             int v = static_cast<int> (Strtol (Tmp.c_str (), &end,10));             result.push_back (v);             p = strtok (Null, split);         }        return result;    }         int compareversion (string version1, string  version2)  {        vector<int> vecint1 =  stringsplit (Version1, ".");         vector<int> vecint2 = stringsplit ( Version2, ".");                 int I;        for (I = 0; i < min (VecInt1.size ( ), Vecint2.size ());  i++)         {             if (Vecint1[i] < vecint2[i])                   return -1;             else if (Vecint1[i] > vecint2[i])                 return 1;         }                 if ( vecint1.size ()  < vecint2.size ())          {            int  j = i; &Nbsp;          for (; J <vecint2.size (); j + +)              {                 if (vecint2[j] > 0)                      return -1 ;            }             return 0;        }         else if (Vecint1.size ()  > vecint2.size ())          {             int j = i;            for (; j  < vecint1.sizE (); j + +)             {                 if (vecint1[j] > 0)                       return 1;            }             return 0;         }        else             return 0;    }};
This article is from the "Do Your best" blog, so be sure to keep this source http://qiaopeng688.blog.51cto.com/3572484/1836522
Leetcode 165. Compare Version Numbers String