generated from codesquad-members-2023/_template-automatic-merge-pr-template
-
Notifications
You must be signed in to change notification settings - Fork 9
[Lily] 4-4w #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
Open
ahnlook
wants to merge
2
commits into
codesquad2023-fe-study:Lily
Choose a base branch
from
ahnlook:Lily
base: Lily
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Lily] 4-4w #40
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,71 @@ | ||
| function solution(s) { | ||
| const words = [ | ||
| 'zero', | ||
| 'one', | ||
| 'two', | ||
| 'three', | ||
| 'four', | ||
| 'five', | ||
| 'six', | ||
| 'seven', | ||
| 'eight', | ||
| 'nine' | ||
| ] | ||
|
|
||
| const str = s.split('') | ||
| let word = '' | ||
| let answer = '' | ||
|
|
||
| for (let i = 0; i < str.length; i++) { | ||
| if (isNaN(str[i])) { | ||
| word += str[i] | ||
| } else { | ||
| answer += str[i] | ||
| continue | ||
| } | ||
|
|
||
| for (let j = 0; j < words.length; j++) { | ||
| if (word === words[j]) { | ||
| answer += j | ||
| word = '' | ||
| break | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return Number(answer) | ||
| } | ||
|
|
||
| solution('one4seveneight') | ||
|
|
||
| // 1. 숫자가 아니어야 한다. | ||
| // 2. 숫자이면 탐색하지 않고 바로 answer에 넣는다. | ||
|
|
||
| // "one4seveneight" 1478 | ||
| // "23four5six7" 234567 | ||
| // "2three45sixseven" 234567 | ||
| // "123" 123 | ||
|
|
||
| function solution(s) { | ||
| let numbers = [ | ||
| 'zero', | ||
| 'one', | ||
| 'two', | ||
| 'three', | ||
| 'four', | ||
| 'five', | ||
| 'six', | ||
| 'seven', | ||
| 'eight', | ||
| 'nine' | ||
| ] | ||
|
|
||
| let answer = s | ||
|
|
||
| for (let i = 0; i < numbers.length; i++) { | ||
| let arr = answer.split(numbers[i]) | ||
| answer = arr.join(i) | ||
|
Comment on lines
+66
to
+67
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. 와... 배열 메서드 활용 짱이네요.. join은 진짜 생각도 못했네 |
||
| } | ||
|
|
||
| return Number(answer) | ||
| } | ||
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,26 @@ | ||
| function solution(s) { | ||
| const stack = [0] | ||
|
|
||
| for (let i = 0; i < s.length; i++) { | ||
| if (stack[stack.length - 1] === s[i]) { | ||
| stack.pop() | ||
| continue | ||
| } | ||
|
|
||
| stack.push(s[i]) | ||
| } | ||
|
|
||
| return stack.length === 1 ? 1 : 0 | ||
| } | ||
|
|
||
| solution('baabaa') | ||
| // return 1 | ||
|
|
||
| // 1. 문자열에서 같은 알파벳이 2개 붙어 있는 짝을 찾는다. | ||
| // 2. 그 둘을 제거한 뒤, 앞 뒤로 문자열을 이어 붙인다. | ||
| // 3. 위 과정을 반복한다. | ||
| // 4. 반복 문자열을 모두 제거했다면 짝지어 제거하기가 종료된다. | ||
| // 5. 문자열이 모두 제거되면 1, 아니면 0을 리턴한다. | ||
|
|
||
| // 문자열이 엄청 작거나 엄청 크거나에 대해서 생각해봐야 한다. | ||
| // 문자열이 아예 없을 수도 있다? |
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,21 @@ | ||
| function solution(t, p) { | ||
| const len = p.length | ||
| let answer = 0 | ||
|
|
||
| for (let i = 0; i <= t.length - len; i++) { | ||
| const numbers = t.slice(i, i + p.length) | ||
| if (+numbers <= +p) { | ||
|
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. 헉 Number 타입으로 바꿔주는 디테일 배워갑니다!!! |
||
| answer++ | ||
| } | ||
| } | ||
|
|
||
| return answer | ||
| } | ||
|
|
||
| solution('3141592', '271') | ||
| // solution('500220839878', '7') | ||
| // solution('3141592', '271') | ||
| // t p result | ||
| // "3141592" "271" 2 | ||
| // "500220839878" "7" 8 | ||
| // "10203" "15" 3 | ||
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,40 @@ | ||
| solution([1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5], 'right') | ||
| // right | ||
| // "LRLLLRLLRRL" | ||
|
|
||
| function solution(numbers, hand) { | ||
| var answer = '' | ||
| const left = [1, 4, 7] | ||
| const right = [3, 6, 9] | ||
| let leftPosition = 0 | ||
| let rightPosition = 0 | ||
|
|
||
| numbers.forEach(number => { | ||
| if (left.includes(number)) { | ||
| leftPosition = number | ||
| answer += 'L' | ||
| return | ||
| } | ||
|
|
||
| if (right.includes(number)) { | ||
| rightPosition = number | ||
| answer += 'R' | ||
| return | ||
| } | ||
|
|
||
| const diffLeft = Math.abs(number - leftPosition) | ||
| const diffRight = Math.abs(number - rightPosition) | ||
|
|
||
| if (diffLeft < diffRight) { | ||
| answer += 'L' | ||
| leftPosition = number | ||
| } else if (diffLeft > diffRight) { | ||
| answer += 'R' | ||
| rightPosition = number | ||
| } else { | ||
| answer += hand === 'right' ? 'R' : 'L' | ||
| } | ||
| }) | ||
|
|
||
| return answer | ||
| } |
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.
객체로 키, 값을 주는것만 생각하고 배열로 간단하게 인덱스 값으로 해당 words의 숫자를 주는 생각을 못했네요. 하드코딩 적어지고 심플하고 좋네요!