-
-
Notifications
You must be signed in to change notification settings - Fork 195
[Paragon0107] Week2 #749
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
[Paragon0107] Week2 #749
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c7e4d2d
Paragon0107 218 solution
paragon0107 e101f27
Paragon0107 230 solution
paragon0107 b366ad7
Paragon0107 230 solution
paragon0107 a220ed7
Paragon0107 218 solution
paragon0107 629c125
Paragon0107 218 solution
paragon0107 c0ac47b
Merge branch 'main' of https://github.com/DaleStudy/leetcode-study
paragon0107 c10be0d
paragon0107 s3sum
paragon0107 4e87445
Merge branch 'main' of https://github.com/DaleStudy/leetcode-study
paragon0107 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,28 @@ | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
class Solution { | ||
public List<List<Integer>> threeSum(int[] nums) { | ||
Set<List<Integer>> set = new HashSet<>(); | ||
Arrays.sort(nums); | ||
for (int i = 0; i < nums.length-2; i++) { | ||
int start = i + 1; | ||
int end = nums.length - 1; | ||
while (start < end) { | ||
int sum = nums[i] + nums[start] + nums[end]; | ||
if (sum < 0 ) { | ||
start++; | ||
} else if (sum > 0) { | ||
end--; | ||
}else { | ||
set.add(Arrays.asList(nums[i], nums[start], nums[end])); | ||
start++; | ||
end--; | ||
} | ||
} | ||
} | ||
return set.stream().toList(); | ||
} | ||
} |
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,19 @@ | ||
/* | ||
* | ||
* 시간 복잡도: | ||
* 바텀업 형식으로 배열을 훑으며 올라가기 때문에 O(N) | ||
* 공간 복잡도: | ||
* 자연수 마다 해당하는 방법의 갯수를 저장하기 때문에 O(N) | ||
* | ||
* */ | ||
class Solution { | ||
public int climbStairs(int n) { | ||
int[] dp = new int[n + 1]; | ||
dp[1] = 1; | ||
dp[2] = 2; | ||
for(int i=3;i<=n;i++){ | ||
dp[i] = dp[i - 2] + dp[i - 1]; | ||
} | ||
return dp[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,18 @@ | ||
import java.util.Arrays; | ||
/* | ||
* 시간 복잡도: | ||
* toCharArray는 O(1)의 복잡도를 갖고 ArraySor의 경우 평균O(nlogn), 최악O(n^2)를 갖음(코테시 몇으로 계산하고 진행해야 할 지는 잘 모르겠네요..) | ||
* 공간 복잡도: | ||
* s와t를 사용해서 그대로 배열로 만들기 때문에 O(n) | ||
* | ||
* | ||
* */ | ||
class Solution { | ||
public static boolean isAnagram(String s, String t) { | ||
char[] s1 = s.toCharArray(); | ||
char[] s2 = t.toCharArray(); | ||
Arrays.sort(s1); | ||
Arrays.sort(s2); | ||
return Arrays.equals(s1, s2); | ||
} | ||
} |
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.
저도 잘 몰라서 찾아봤는데, 자바 8이상에서는 parallelSort를 사용하면 시간 복잡도를 O(n logn)으로 개선할 수 있다고 하네요!