Why is my codes wrong here? but it works well at eclipse


  • 0
    K

    public class Solution {
    public int compareVersion(String version1, String version2) {

        String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");
        
        int h1 = Integer.valueOf(v1[0]);
        int t1 = Integer.valueOf(v1[1]);
        
        int h2 = Integer.valueOf(v2[0]);
        int t2 = Integer.valueOf(v2[1]);
        
        //comparison
        if(h1 > h2){
            return 1;
        }else if(h1 < h2){
            return -1;
        }else{
            if(t1 > t2)
                return 1;
            else if(t1 < t2)
                return -1;
            else
                return 0;
        }
    }
    

    }


  • 1
    K

    The version numbers can have more or less "levels" than 2. For example it can be: "1", "1.12", "1.2.3.4.5", etc.

    And you just assume its always like: 11.11, 12.2, 1.13, etc.


  • 0
    G

    Take the whole array (v1 and v2) into consideration.


Log in to reply
 

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