JAVA 0ms O(n) Solution


  • 0
    H
    
        public int compareVersion(String version1, String version2) {
        	char [] ss1 = version1.toCharArray();
        	char [] ss2 = version2.toCharArray();
        	int i=0,j=0;
        	int ver1 = 0 ;
        	int ver2 = 0 ;
        	while(i<ss1.length||j<ss2.length){
        		while(i<ss1.length){
        			if(ss1[i]!=46){
        				ver1=ver1*10+(ss1[i]-48);
        				i++;
        			}else{
        				i++;
        				break;
        			}
        		}
        		while(j<ss2.length){
        			if(ss2[j]!=46){
        				ver2=ver2*10+(ss2[j]-48);
        				j++;
        			}else{
        				j++;
        				break;
        			}
        		}
        		if(ver1>ver2)
        			return 1;
        		else if(ver1<ver2)
        			return -1;
        		else{
        			ver1=0;
        			ver2=0;
        			continue;
        		}
        	
        	}
        	return 0;
        		
        }
    
    

  • 0
    H

    up up
    hope someone who can give some directions.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.