Skip to content

Commit ce26df6

Browse files
authored
Merge pull request #1731 from renovizee/main
[renovziee] WEEK 02 Solutions
2 parents b9f382b + eca2f02 commit ce26df6

File tree

7 files changed

+169
-0
lines changed

7 files changed

+169
-0
lines changed

3sum/renovizee.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.List;
2+
3+
4+
// tag renovizee 2week unresolved
5+
// https://github.com/DaleStudy/leetcode-study/issues/241
6+
// https://leetcode.com/problems/3sum/
7+
class Solution {
8+
// Solv1 :
9+
// 시간복잡도 : O(n)
10+
// 공간복잡도 : O(n)
11+
public List<List<Integer>> threeSum(int[] nums) {
12+
13+
}
14+
}
15+
16+
//-------------------------------------------------------------------------------------------------------------
17+
// Java 문법 피드백
18+
//
19+
//-------------------------------------------------------------------------------------------------------------

climbing-stairs/renovizee.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
3+
4+
// tag renovizee 2week
5+
// https://github.com/DaleStudy/leetcode-study/issues/230
6+
// https://leetcode.com/problems/climbing-stairs/ #70 #Easy
7+
class Solution {
8+
// Solv1
9+
// 시간복잡도 : O(n)
10+
// 공간복잡도 : O(n)
11+
public int climbStairs(int n) {
12+
int[] dp = new int[]{1, 2};
13+
14+
if (n == dp[0]) {
15+
return dp[0];
16+
}
17+
18+
if (n == dp[1]) {
19+
return dp[1];
20+
}
21+
22+
for (int i = 3; i <= n; i++) {
23+
int nextWayCount = dp[0] + dp[1];
24+
dp[0] = dp[1];
25+
dp[1] = nextWayCount;
26+
}
27+
28+
return dp[1];
29+
30+
}
31+
}
32+
//-------------------------------------------------------------------------------------------------------------
33+
// Java 문법 피드백
34+
// 1) Math.pow(2, 3) 2의 3승.
35+
//-------------------------------------------------------------------------------------------------------------

house-robber/renovizee.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

2+
// tag renovizee 1week unresolved
23
// https://github.com/DaleStudy/leetcode-study/issues/264
34
// https://leetcode.com/problems/house-robber/
5+
// DP 자체에 대한 설명 : https://www.youtube.com/watch?v=0bqfTzpWySY
46
class Solution {
57
public int rob(int[] nums) {
68

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
3+
// tag renovizee 2week
4+
// https://github.com/DaleStudy/leetcode-study/issues/239
5+
// https://leetcode.com/problems/product-of-array-except-self/ #238 #Medium
6+
class Solution {
7+
// Solv1 :
8+
// 시간복잡도 : O(n)
9+
// 공간복잡도 : O(n)
10+
public int[] productExceptSelf(int[] nums) {
11+
12+
boolean isZero = false;
13+
int zeroIndex = 0;
14+
15+
int productExceptZero = 1;
16+
for (int i = 0; i < nums.length; i++) {
17+
if (nums[i] == 0) {
18+
if (isZero) { // zero가 2개면 모든 원소가 0임.
19+
return new int[nums.length];
20+
}
21+
zeroIndex = i;
22+
isZero = true;
23+
} else {
24+
productExceptZero *= nums[i];
25+
}
26+
}
27+
28+
int[] result = new int[nums.length];
29+
for (int i = 0; i < nums.length; i++) {
30+
if (isZero) {
31+
if (i != zeroIndex) {
32+
result[i] = 0;
33+
} else {
34+
result[i] = productExceptZero;
35+
}
36+
} else {
37+
result[i] = productExceptZero / nums[i];
38+
}
39+
40+
}
41+
return result;
42+
}
43+
44+
}
45+
46+
//-------------------------------------------------------------------------------------------------------------
47+
// Java 문법 피드백
48+
//
49+
//-------------------------------------------------------------------------------------------------------------

top-k-frequent-elements/renovizee.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11

2+
// tag renovizee 1week unresolved
23
// https://github.com/DaleStudy/leetcode-study/issues/237
34
// https://leetcode.com/problems/top-k-frequent-elements/
45
class Solution {
6+
57
public int[] topKFrequent(int[] nums, int k) {
68
int[] result = {1, 2, 3};
79

valid-anagram/renovizee.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.Arrays;
2+
3+
// tag renovizee 2week
4+
// https://github.com/DaleStudy/leetcode-study/issues/218
5+
// https://leetcode.com/problems/valid-anagram/ #242 #Easy
6+
class Solution {
7+
// Solv1
8+
// 시간복잡도 : O(n)
9+
// 공간복잡도 : O(n)
10+
public boolean isAnagram(String s, String t) {
11+
12+
char[] sChars = s.toCharArray();
13+
char[] tChars = t.toCharArray();
14+
15+
Arrays.sort(sChars);
16+
Arrays.sort(tChars);
17+
18+
return Arrays.equals(sChars, tChars);
19+
}
20+
}
21+
22+
//-------------------------------------------------------------------------------------------------------------
23+
// Java 문법 피드백
24+
// 1) string.toCharArray
25+
// 2) Arrays.~ 문법 ~.sort ~.equals
26+
// 3) Arrays.
27+
//-------------------------------------------------------------------------------------------------------------
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
3+
// tag renovizee 2week
4+
// https://github.com/DaleStudy/leetcode-study/issues/251
5+
// https://leetcode.com/problems/validate-binary-search-tree/
6+
class Solution {
7+
8+
/**
9+
* Definition for a binary tree node.
10+
* public class TreeNode {
11+
* int val;
12+
* TreeNode left;
13+
* TreeNode right;
14+
* TreeNode() {}
15+
* TreeNode(int val) { this.val = val; }
16+
* TreeNode(int val, TreeNode left, TreeNode right) {
17+
* this.val = val;
18+
* this.left = left;
19+
* this.right = right;
20+
* }
21+
* }
22+
*/
23+
24+
// Solv1 :
25+
// 시간복잡도 : O(n)
26+
// 공간복잡도 : O(n)
27+
public boolean isValidBST(TreeNode root) {
28+
29+
}
30+
}
31+
32+
//-------------------------------------------------------------------------------------------------------------
33+
// Java 문법 피드백
34+
//
35+
//-------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)