Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUMUNYEONG] Week4 Solutions #417

Merged
merged 8 commits into from
Sep 7, 2024
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
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) -> 최선의 경우 O(n) 이지만, 평균적으로 O(n log n)
// 빠진 숫자를 찾기위해서 순회 (최대길이 n)
// 따라서 시간 복잡도는 최대 O(n log n)

// 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 = normalize(s);
let reverseStr = "";

function normalize(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)
// normalize 함수에서 n번(s의길이) 순회(toLowerCase) + n번 순회(replace)
// reverseStr 을 만들기 위해서 for문 - 길이 n
// = O(3n) 따라서 O(n)

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