-
-
Notifications
You must be signed in to change notification settings - Fork 245
[GUMUNYEONG] Week4 Solutions #417
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
Changes from 5 commits
a6f2dd8
edd1ee6
abbf59a
971815e
90b2c50
1f19ed8
8ccbeb1
6231903
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
|
||
// SC | ||
// 길이가 n인 배열을 저장할 공간 필요 | ||
// O(n) |
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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 전처리 기능을 별도 함수로 분리하고자 하는 의도이실까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정렬을 위한 순회가 최선의 경우에는 Ω(n)이긴 하지만, 평균적으로는 결과가 달라지기 때문에 수정이 필요해 보입니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 넵 제가 생각이 짧았던 부분이네요..! 정렬 함수의 시간 복잡도에 대해서 자세히 알아봐야겠습니다. 피드백 감사합니다..!