a slight alternative. Not sure whether the approaches have a different time complexity or not. You could help me with that?
var longestCommonPrefix = function(strs) { if(strs.length==0) return ""; let pre = strs[0]; var newpre = ''; for (s of strs) { newpre=''; for (let i=0; i<Math.min(s.length, pre.length); i++) { if (s[i]==pre[i]) { newpre+=s[i]; } else { break; } } pre = newpre; } return newpre; };
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
a slight alternative. Not sure whether the approaches have a different time complexity or not. You could help me with that?