knakul853

Untitled

Jun 19th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. /**
  2. knakul853
  3. **/
  4. class Solution {
  5. public:
  6.     int compareVersion(string s1, string s2) {
  7.        
  8.        
  9.         int n = s1.size();
  10.         int m = s2.size();
  11.         int i=0,j=0;
  12.        
  13.         while( i<n || j<m )
  14.         {
  15.             int num1 = 0;
  16.             int num2 = 0;
  17.            
  18.             while( i < n&& s1[i]!='.')
  19.             {
  20.                 num1 = num1*10 + (s1[i]-'0');
  21.                 i++;
  22.             }
  23.               while( j < m && s2[j]!='.')
  24.             {
  25.                 num2 = num2*10 + (s2[j]-'0');
  26.                 j++;
  27.             }
  28.            
  29.             if(num1 > num2) return 1;
  30.             if(num1 < num2) return -1;
  31.             num1 = 0;
  32.             num2 = 0;
  33.             i++;
  34.             j++;
  35.         }
  36.        
  37.         return 0;
  38.     }
  39. };
Add Comment
Please, Sign In to add comment