JAVA AC score tracking solution


  • 0
    W
        public int compareVersion(String version1, String version2) {
            Long score1 = 0L;
            Long score2 = 0L;
    
            String[] parts1 = version1.split("\\.");
            String[] parts2 = version2.split("\\.");
            int maxLen = Math.max(parts1.length, parts2.length);
            
            Long multi1 = (long) Math.pow(100, maxLen - 1);
            for (String s : parts1) {
                score1 += multi1 * Long.valueOf(s);
                multi1 /= 100;
            }
            
            Long multi2 = (long) Math.pow(100, maxLen - 1);
            for (String s : parts2) {
                score2 += multi2 * Long.valueOf(s);
                multi2 /= 100;
            }
            
            return score1.compareTo(score2);
        }
    

Log in to reply
 

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