Runtime error on my javascript solution


  • 0
    R

    I tested my code on my local machine using node, but I get a runtime error here on leetcode with my solution. Can anyone give me a hint on why I might be getting a runtime error?

    var longestCommonPrefix = function(strs) {
        return strs[0].split('').reduce(function(longest,_,index,arr) {
          if (strs.every(function(str) {return str[index] !== arr[index] ? false : true;}))
            longest += arr[index];
          return longest;
        },'');
    };
    

Log in to reply
 

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