-
-
Notifications
You must be signed in to change notification settings - Fork 360
[seongmin36] WEEK 02 Solutions #2690
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
seongmin36
wants to merge
10
commits into
DaleStudy:main
Choose a base branch
from
seongmin36:main
base: main
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.
+83
−0
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1912b25
contains duplicate solution
seongmin36 b9fcfd4
two sum solution
seongmin36 10ff2ee
Top K Frequent Elements solution
seongmin36 2aa8722
longest consecutive sequence solution
seongmin36 40d8496
house robber solution
seongmin36 29dfd91
apply feedback from code review
seongmin36 96f2e5f
valid anagram solution
seongmin36 508b33d
climbing stairs solution
seongmin36 c02aae1
product of array except self solution
seongmin36 075b911
Merge branch 'DaleStudy:main' into main
seongmin36 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,18 @@ | ||
| /** | ||
| * @param {number} n | ||
| * @return {number} | ||
| */ | ||
| function climbStairs(n) { | ||
| if (n <= 2) return n; | ||
|
|
||
| let arr = new Array(n + 1); | ||
|
|
||
| arr[0] = 1; | ||
| arr[1] = 2; | ||
|
|
||
| for (let i = 2; i < arr.length; i++) { | ||
| arr[i] = arr[i - 2] + arr[i - 1]; | ||
| } | ||
|
|
||
| return arr[n - 1]; | ||
| } |
|
Contributor
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,34 @@ | ||
| /** | ||
| 문제의 핵심은 '어떻게 인덱스와 곱을 이중 반복문을 쓰지 않고 해결하느냐'다. 'Goal' → 시간 복잡도 : O(N) | ||
| 여기서 사용된 개념: 'Two Pointer' | ||
| Two Pointer? → '배열에서 순차적으로 접근해야 할 때 두 개의 점의 위치를 기록하면서 처리하는 알고리즘' | ||
| 이중 반복을 사용하지 않고, 각 인덱스를 순회하면서 answer[index]에 본인을 제외한 곱셈을 중첩시킨다. | ||
| 본인을 제외한 나머지 원소의 곱이기 때문에 left와 right로 나눠서 중첩된 곱셈을 다시 곱한다. | ||
| */ | ||
|
|
||
| /** | ||
| * @param {number[]} nums | ||
| * @return {number[]} | ||
| */ | ||
| function productExceptSelf(nums) { | ||
| let answer = new Array(nums.length).fill(1); | ||
|
|
||
| let left = 0; | ||
| let right = nums.length - 1; | ||
|
|
||
| let mul_left = 1; | ||
| let mul_right = 1; | ||
|
|
||
| while (left < nums.length && right >= 0) { | ||
| answer[left] *= mul_left; | ||
| mul_left *= nums[left]; // 자기 자신 제외 곱 | ||
|
|
||
| answer[right] *= mul_right; | ||
| mul_right *= nums[right]; | ||
|
|
||
| left++; | ||
| right--; | ||
| } | ||
|
|
||
| return answer; | ||
| } |
|
Contributor
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,31 @@ | ||
| /** | ||
| 결국 같아야 것은 string의 길이와 안에 들어간 각 character의 갯수다. | ||
| 즉, s와 t의 문자의 갯수와 같으면 된다. | ||
| map을 사용하여 key와 value자리에 각각 문자, 갯수를 받는다. | ||
| s와 t를 비교하며 해당하는 문자 갯수-1을 한다. | ||
| 각 key의 value를 문제없이 차감했다면 true를 반환. 그 외 false를 반환 | ||
| */ | ||
|
|
||
| /** | ||
| * @param {string} s | ||
| * @param {string} t | ||
| * @return {boolean} | ||
| */ | ||
| function isAnagram(s, t) { | ||
| if (s.length !== t.length) return false; | ||
|
|
||
| let map_s = new Map(); | ||
|
|
||
| for (let char of s) { | ||
| map_s.set(char, (map_s.get(char) || 0) + 1); | ||
| } | ||
|
|
||
| for (let char of t) { | ||
| if (!map_s.has(char) || map_s.get(char) === 0) { | ||
| return false; | ||
| } | ||
| map_s.set(char, map_s.get(char) - 1); | ||
| } | ||
|
|
||
| return true; | ||
| } |
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
풀이 1:
climbStairs— Time: O(n) / Space: O(n)피드백: 배열을 사용해 연속된 두 값의 합으로 계단 수를 계산한다.
개선 제안: 현재 구현이 적절해 보입니다.
풀이 2:
productExceptSelf— Time: O(n) / Space: O(1)피드백: 왼쪽과 오른쪽 누적 곱을 이용해 한 번의 순회로 결과를 얻는다.
개선 제안: 현재 구현이 적절해 보입니다.
풀이 3:
isAnagram— Time: O(n) / Space: O(n)피드백: 길이 검사 후 맵을 통해 각 문자 카운트를 증가/감소시키는 방식이다.
개선 제안: 현재 구현이 적절해 보입니다.