Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions sik9252/LongestCommonPrefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var longestCommonPrefix = function (strs) {
if (strs.length === 0) return "";

for (let i = 0; i < strs[0].length; i++) {
const char = strs[0][i];

for (let j = 1; j < strs.length; j++) {
if (strs[j][i] !== char) {
return strs[0].slice(0, i);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slice 좋네요!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 이런 방법도 있군요 !!!! 지니어스..

}
}
}

return strs[0];
};
11 changes: 11 additions & 0 deletions sik9252/SingleNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var singleNumber = function (nums) {
const map = new Map();

for (const num of nums) {
map.set(num, (map.get(num) || 0) + 1);
}

for (const [num, count] of map) {
if (count === 1) return num;
}
};
Loading