-
-
Notifications
You must be signed in to change notification settings - Fork 247
[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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a6f2dd8
valid-palindrome
edd1ee6
valid-palindrome
abbf59a
Merge remote-tracking branch 'upstream/main'
971815e
missing-number
90b2c50
Merge remote-tracking branch 'upstream/main'
1f19ed8
Merge remote-tracking branch 'upstream/main'
8ccbeb1
missing-number
6231903
valid-palindrome
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
전처리 기능을 별도 함수로 분리하고자 하는 의도이실까요?
그렇다면
preprocess
,sanitize
,normalize
등의 작명도 활용하실 수 있을 것 같아요사실상 한 줄 짜리 함수이다 보니 인라인도 충분히 괜찮지 않을까 해서 의견 드립니다!
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.
네 가독성이 더 좋다고 판단해서 함수를 따로 빼봤습니다..! 항상 변수명과 함수명을 작성하는데 있어서 어려움을 느끼곤 하는데, 추천해주셔서 감사합니다