Skip to content

Commit

Permalink
Merge pull request #749 from paragon0107/main
Browse files Browse the repository at this point in the history
[Paragon0107] Week2
  • Loading branch information
paragon0107 authored Dec 21, 2024
2 parents f231299 + 4e87445 commit 2d55165
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 3sum/paragon0107.java
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();
}
}
19 changes: 19 additions & 0 deletions climbing-stairs/paragon0107_230.java
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];
}
}
18 changes: 18 additions & 0 deletions valid-anagram/paragon0107_218.java
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);
}
}

0 comments on commit 2d55165

Please sign in to comment.