-
Notifications
You must be signed in to change notification settings - Fork 1
[WEEK09] 최준호 #40
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
[WEEK09] 최준호 #40
Changes from all commits
Commits
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,37 @@ | ||
| function solution(s) { | ||
| const isNumber = (v) => { | ||
| return "0" <= v && v <= "9"; | ||
| }; | ||
|
|
||
| return s | ||
| .split(" ") | ||
| .map((v) => { | ||
| if (v === "") return ""; | ||
|
|
||
| if (isNumber(v[0])) { | ||
| return v.toLowerCase(); | ||
| } else { | ||
| const str = v.toLowerCase(); | ||
| const first = str[0].toUpperCase(); | ||
|
|
||
| return first + str.slice(1, str.length); | ||
| } | ||
| }) | ||
| .join(" "); | ||
| } | ||
|
|
||
| /* | ||
| 풀이 시간: 21분 | ||
|
|
||
| 시간 복잡도는 O(n)이다. | ||
| 공간 복잡도는 O(n)이다. | ||
|
|
||
| 문자열을 공백으로 분리해서 배열로 만들고, 배열의 요소들을 순회하면서, 각 요소의 첫 번째 문자가 숫자인지 확인했다. | ||
| 만약 첫 번째 문자가 숫자라면, 해당 요소를 소문자로 변환해서 반환했다. | ||
| 만약 첫 번째 문자가 숫자가 아니라면, 해당 요소를 소문자로 변환한 뒤에, 첫 번째 문자를 대문자로 변환해서 반환했다. | ||
| 마지막으로, 배열의 요소들을 공백으로 연결해서 반환했다. | ||
|
|
||
| 숫자인지를 확인하는 과정에서 문자열 숫자를 판단해야 되는데 숫자를 판단하고 있었다. | ||
| 또한, spilt(' ')으로 나누면 맨 앞이 공백이 될 수 있다는 것을 간과하여 시간이 오래 걸렸다. | ||
| 맨 앞이 숫자거나 문자거나 상관없이 대문자로 만들어도 문제가 없을 것 같다. | ||
| */ |
|
Collaborator
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. 저도 다음에 비슷한 문제 나오면 증감 방식으로 푸는 방법도 기억하고 적용해봐야겠어요! |
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,32 @@ | ||
| function solution(s) { | ||
| let score = 0; | ||
| let index = 0; | ||
|
|
||
| if (s[0] === ")") return false; | ||
|
|
||
| while (s.length > index) { | ||
| if (s[index] === "(") score++; | ||
| else score--; | ||
|
|
||
| if (score < 0) return false; | ||
|
|
||
| index++; | ||
| } | ||
|
|
||
| return score === 0 ? true : false; | ||
| } | ||
|
Member
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. 스택 말고도 증감식으로 카운팅하는것도 좋은 거 같아요 👍 |
||
|
|
||
| /* | ||
| 풀이 시간: 9분 | ||
|
|
||
| 시간 복잡도는 O(n)이다. | ||
| 공간 복잡도는 O(1)이다. | ||
|
|
||
| 문자열을 순회하면서, "("가 나오면 score를 1 증가시키고, ")"가 나오면 score를 1 감소시켰다. | ||
| 만약 score가 음수가 되는 경우에는 false를 반환했다. | ||
| 문자열을 모두 순회한 후에는 score가 0인지 확인해서, 0이면 true를 반환하고, 그렇지 않으면 false를 반환했다. | ||
|
|
||
|
|
||
| 기존에 풀이 방법을 암기하고 있어서 쉽게 떠올릴 수 있었다. | ||
| 보통 stack을 이용해서 풀이하는 방법이 있지만, 효율성 면에서 score를 이용해서 풀이하는 방법이 더 좋은 것 같다. | ||
| */ | ||
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 @@ | ||
| function solution(s) { | ||
| const arr = s.split(" ").map((n) => Number(n)); | ||
| const min = Math.min(...arr); | ||
| const max = Math.max(...arr); | ||
|
|
||
| return min.toString() + " " + max.toString(); | ||
| } | ||
|
|
||
| /* | ||
| 풀이 시간: 7분 | ||
|
|
||
| 시간 복잡도는 O(n)이다. | ||
| 공간 복잡도는 O(n)이다. | ||
|
|
||
| 문자열을 공백으로 분리해서 배열로 만들고, 배열의 요소들을 숫자로 변환했다. | ||
| 그 다음에, Math.min과 Math.max를 사용해서 배열에서 최솟값과 최댓값을 구했다. | ||
| 마지막으로, 최솟값과 최댓값을 문자열로 변환해서 공백으로 연결해서 반환했다. | ||
|
|
||
| 정답률이 높은 순으로 풀다 보니 초반 문제는 쉽게 풀 수 있을 것 같다. | ||
| 후반으로 갈수록 점점 더 어려워질 텐데 걱정이다. | ||
| 쉬운 문제와 어려운 문제를 섞어서 풀어야 할지 고민이 된다. | ||
| */ |
Oops, something went wrong.
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.
index 변수를 하나 더 두어 while 문으로도 처리할 수 있군요. 제가 for문만 자주 사용하는 편인데 유연한 사고를 배우게 되었습니다!