Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
thesunnatillo committed Nov 1, 2024
1 parent 9b3652d commit c104a41
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions javascript/longest-common-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
* @return {string}
*/
var longestCommonPrefix = function(strs) {
if (strs.length === 0) return "";

let count = 0;

};
let prefix = strs[0];

for (let i = 1; i < strs.length; i++) {
while (strs[i].indexOf(prefix) !== 0) {
prefix = prefix.substring(0, prefix.length - 1);
if (prefix === "") return "";
}
}
return prefix;
};

0 comments on commit c104a41

Please sign in to comment.