Run code is correct, submit solution is wrong?? JavaScript


  • 0
    P

    When i run the code i get the correct answer, however, when i submit the solution i get the wrong answer.
    Here is the code:

     * @param {string} s
     * @return {number}
     */
    var lengthOfLongestSubstring = function(s) {
        assocArr = {};
        for(var x = 0; x < s.length; x++){
            if (!(s[x] in assocArr )){
                assocArr[s[x]] += 1;
            }else if (assocArr[s[x]] >= 1){
                continue;
            }
        }
        
        finishedArray = [];
        var increment = 0;
        for(var key in assocArr){
            finishedArray[increment] = key;
            increment += 1;
        }
        
        return finishedArray.length;
    };```

Log in to reply
 

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