Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
22 changes: 22 additions & 0 deletions missing-number/GUMUNYEONG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @param {number[]} nums
* @return {number}
*/
var missingNumber = function (nums) {
nums = nums.sort();

for (let i = 0; i < nums.length; i++) {
if (nums[i] !== i) return i;
}

return nums.length;
};

// TC
// nums 정렬을 하기 위해서 순회 (길이 n)
// 빠진 숫자를 찾기위해서 순회 (최대길이 n)
// O(2n) 따라서 시간 복잡도는 O(n)
Copy link
Contributor

Choose a reason for hiding this comment

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

정렬을 위한 순회가 최선의 경우에는 Ω(n)이긴 하지만, 평균적으로는 결과가 달라지기 때문에 수정이 필요해 보입니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

앗 넵 제가 생각이 짧았던 부분이네요..! 정렬 함수의 시간 복잡도에 대해서 자세히 알아봐야겠습니다. 피드백 감사합니다..!


// SC
// 길이가 n인 배열을 저장할 공간 필요
// O(n)
31 changes: 31 additions & 0 deletions valid-palindrome/GUMUNYEONG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @param {string} s
* @return {boolean}
*/
var isPalindrome = function (s) {

let str = newStr(s);
let reverseStr = "";

function newStr(str) {
str = str.toLowerCase().replace(/[^a-z0-9]/g, "");

return str;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

전처리 기능을 별도 함수로 분리하고자 하는 의도이실까요?
그렇다면 preprocess, sanitize, normalize 등의 작명도 활용하실 수 있을 것 같아요
사실상 한 줄 짜리 함수이다 보니 인라인도 충분히 괜찮지 않을까 해서 의견 드립니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네 가독성이 더 좋다고 판단해서 함수를 따로 빼봤습니다..! 항상 변수명과 함수명을 작성하는데 있어서 어려움을 느끼곤 하는데, 추천해주셔서 감사합니다



for (let i = str.length - 1; i >= 0; i--) {
reverseStr += str[i];
};


return str === reverseStr;
};

// TC : O(n)
// newStr 함수에서 n번(s의길이) 순회(toLowerCase) + n번 순회(replace)
// reverseStr 을 만들기 위해서 for문 - 길이 n
// = O(3n) 따라서 O(n)

// SC : O(n)
// 변수 str , reversStr 모두 길이가 n 이므로 O(n)