diff --git a/3sum/renovizee.java b/3sum/renovizee.java new file mode 100644 index 000000000..74bc5b637 --- /dev/null +++ b/3sum/renovizee.java @@ -0,0 +1,19 @@ +import java.util.List; + + +// tag renovizee 2week unresolved +// https://github.com/DaleStudy/leetcode-study/issues/241 +// https://leetcode.com/problems/3sum/ +class Solution { + // Solv1 : + // 시간복잡도 : O(n) + // 공간복잡도 : O(n) + public List> threeSum(int[] nums) { + + } +} + +//------------------------------------------------------------------------------------------------------------- +// Java 문법 피드백 +// +//------------------------------------------------------------------------------------------------------------- diff --git a/climbing-stairs/renovizee.java b/climbing-stairs/renovizee.java new file mode 100644 index 000000000..caa20a731 --- /dev/null +++ b/climbing-stairs/renovizee.java @@ -0,0 +1,35 @@ + + + +// tag renovizee 2week +// https://github.com/DaleStudy/leetcode-study/issues/230 +// https://leetcode.com/problems/climbing-stairs/ #70 #Easy +class Solution { + // Solv1 + // 시간복잡도 : O(n) + // 공간복잡도 : O(n) + public int climbStairs(int n) { + int[] dp = new int[]{1, 2}; + + if (n == dp[0]) { + return dp[0]; + } + + if (n == dp[1]) { + return dp[1]; + } + + for (int i = 3; i <= n; i++) { + int nextWayCount = dp[0] + dp[1]; + dp[0] = dp[1]; + dp[1] = nextWayCount; + } + + return dp[1]; + + } +} +//------------------------------------------------------------------------------------------------------------- +// Java 문법 피드백 +// 1) Math.pow(2, 3) 2의 3승. +//------------------------------------------------------------------------------------------------------------- diff --git a/house-robber/renovizee.java b/house-robber/renovizee.java index 85f796d42..a3c358b74 100644 --- a/house-robber/renovizee.java +++ b/house-robber/renovizee.java @@ -1,6 +1,8 @@ +// tag renovizee 1week unresolved // https://github.com/DaleStudy/leetcode-study/issues/264 // https://leetcode.com/problems/house-robber/ +// DP 자체에 대한 설명 : https://www.youtube.com/watch?v=0bqfTzpWySY class Solution { public int rob(int[] nums) { diff --git a/product-of-array-except-self/renovizee.java b/product-of-array-except-self/renovizee.java new file mode 100644 index 000000000..1bf09d501 --- /dev/null +++ b/product-of-array-except-self/renovizee.java @@ -0,0 +1,49 @@ + + +// tag renovizee 2week +// https://github.com/DaleStudy/leetcode-study/issues/239 +// https://leetcode.com/problems/product-of-array-except-self/ #238 #Medium +class Solution { + // Solv1 : + // 시간복잡도 : O(n) + // 공간복잡도 : O(n) + public int[] productExceptSelf(int[] nums) { + + boolean isZero = false; + int zeroIndex = 0; + + int productExceptZero = 1; + for (int i = 0; i < nums.length; i++) { + if (nums[i] == 0) { + if (isZero) { // zero가 2개면 모든 원소가 0임. + return new int[nums.length]; + } + zeroIndex = i; + isZero = true; + } else { + productExceptZero *= nums[i]; + } + } + + int[] result = new int[nums.length]; + for (int i = 0; i < nums.length; i++) { + if (isZero) { + if (i != zeroIndex) { + result[i] = 0; + } else { + result[i] = productExceptZero; + } + } else { + result[i] = productExceptZero / nums[i]; + } + + } + return result; + } + +} + +//------------------------------------------------------------------------------------------------------------- +// Java 문법 피드백 +// +//------------------------------------------------------------------------------------------------------------- diff --git a/top-k-frequent-elements/renovizee.java b/top-k-frequent-elements/renovizee.java index 214c3d817..3c115e4c5 100644 --- a/top-k-frequent-elements/renovizee.java +++ b/top-k-frequent-elements/renovizee.java @@ -1,7 +1,9 @@ +// tag renovizee 1week unresolved // https://github.com/DaleStudy/leetcode-study/issues/237 // https://leetcode.com/problems/top-k-frequent-elements/ class Solution { + public int[] topKFrequent(int[] nums, int k) { int[] result = {1, 2, 3}; diff --git a/valid-anagram/renovizee.java b/valid-anagram/renovizee.java new file mode 100644 index 000000000..412e75a05 --- /dev/null +++ b/valid-anagram/renovizee.java @@ -0,0 +1,27 @@ +import java.util.Arrays; + +// tag renovizee 2week +// https://github.com/DaleStudy/leetcode-study/issues/218 +// https://leetcode.com/problems/valid-anagram/ #242 #Easy +class Solution { + // Solv1 + // 시간복잡도 : O(n) + // 공간복잡도 : O(n) + public boolean isAnagram(String s, String t) { + + char[] sChars = s.toCharArray(); + char[] tChars = t.toCharArray(); + + Arrays.sort(sChars); + Arrays.sort(tChars); + + return Arrays.equals(sChars, tChars); + } +} + +//------------------------------------------------------------------------------------------------------------- +// Java 문법 피드백 +// 1) string.toCharArray +// 2) Arrays.~ 문법 ~.sort ~.equals +// 3) Arrays. +//------------------------------------------------------------------------------------------------------------- diff --git a/validate-binary-search-tree/renovizee.java b/validate-binary-search-tree/renovizee.java new file mode 100644 index 000000000..19c72707d --- /dev/null +++ b/validate-binary-search-tree/renovizee.java @@ -0,0 +1,35 @@ + + +// tag renovizee 2week +// https://github.com/DaleStudy/leetcode-study/issues/251 +// https://leetcode.com/problems/validate-binary-search-tree/ +class Solution { + + /** + * Definition for a binary tree node. + * public class TreeNode { + * int val; + * TreeNode left; + * TreeNode right; + * TreeNode() {} + * TreeNode(int val) { this.val = val; } + * TreeNode(int val, TreeNode left, TreeNode right) { + * this.val = val; + * this.left = left; + * this.right = right; + * } + * } + */ + + // Solv1 : + // 시간복잡도 : O(n) + // 공간복잡도 : O(n) + public boolean isValidBST(TreeNode root) { + + } +} + +//------------------------------------------------------------------------------------------------------------- +// Java 문법 피드백 +// +//-------------------------------------------------------------------------------------------------------------