My 2ms java solution, beat beats 87.77%. But the code is not easy to understand


  • 0
    A
    while(version1.length()>0 || version2.length()>0) {
    	int int1 = version1.length()>0?Integer.parseInt(version1.substring(0, version1.indexOf('.')>0?version1.indexOf('.'):version1.length())):0;
    	int int2 = version2.length()>0?Integer.parseInt(version2.substring(0, version2.indexOf('.')>0?version2.indexOf('.'):version2.length())):0;
    	if(int1>int2) return 1;
    	else if(int2>int1) return -1;
    	
    	version1 = version1.indexOf('.')>0?version1.substring(version1.indexOf('.')+1):"";
    	version2 = version2.indexOf('.')>0?version2.substring(version2.indexOf('.')+1):"";
    }
    
    return 0;

Log in to reply
 

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