File tree Expand file tree Collapse file tree 7 files changed +169
-0
lines changed
product-of-array-except-self
validate-binary-search-tree Expand file tree Collapse file tree 7 files changed +169
-0
lines changed Original file line number Diff line number Diff line change 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+ //-------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change 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+ //-------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change 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
46class Solution {
57 public int rob (int [] nums ) {
68
Original file line number Diff line number Diff line change 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+ //-------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change 11
2+ // tag renovizee 1week unresolved
23// https://github.com/DaleStudy/leetcode-study/issues/237
34// https://leetcode.com/problems/top-k-frequent-elements/
45class Solution {
6+
57 public int [] topKFrequent (int [] nums , int k ) {
68 int [] result = {1 , 2 , 3 };
79
Original file line number Diff line number Diff line change 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+ //-------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change 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+ //-------------------------------------------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments