diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/2136. Earliest Possible Day of Full Bloom.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/2136. Earliest Possible Day of Full Bloom.java" new file mode 100644 index 00000000..1c1b0ccf --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/2136. Earliest Possible Day of Full Bloom.java" @@ -0,0 +1,40 @@ +/* +1. 아이디어: + - 모든 꽃을 피우는 가장 짧은 일 수 계산 + - 꽃을 심는 기간동안 다른 꽃을 같이 심을수 없다. + - 그러므로 plantTime은 고정되고 growTime에 따라 기간이 결정 + - growTime이 길수록 먼저 심는게 유리하므로 growTime이 높은순으로 정렬 후 값을 계산한다 + +2. 시간복잡도: O(N) + +3. 자료구조/알고리즘: 그리디 +*/ + +class Solution { + public int earliestFullBloom(int[] plantTime, int[] growTime) { + // 1. 꽃을 심는 작업은 겹칠 수 없다 + // 2. 꽃은 growTime+1에 핀다 + // 3. 꽃을 나눠 심어도 된다 + + List flowers = new ArrayList<>(); + + for(int i=0; i Integer.compare(b[1],a[1])); + + int allBloomingPeriod = flowers.get(0)[0]; + int nextBlooming = flowers.get(0)[1]+1; + + for(int i=1; i Integer.compare(a[2],b[2])); + + parent = new int[n]; + Arrays.fill(parent, -1); + + int link = 0; + + for(int i=0; i parent[rootY]) parent[rootX] = rootY; + else if(parent[rootX] < parent[rootY]) parent[rootY] = rootX; + else { + parent[rootX] = rootY; + parent[rootY]--; + } + + return true; + } +} \ No newline at end of file diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/4074. Maximum Product Pair With Target Sum.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/4074. Maximum Product Pair With Target Sum.java" new file mode 100644 index 00000000..6c6fc96d --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/4074. Maximum Product Pair With Target Sum.java" @@ -0,0 +1,44 @@ +/* + +1. 아이디어 : 조건을 만족하는 원소쌍중 가장 큰 값 구하기 + i,j의 순서는 더 큰 원소 idx가 먼저와야함을 명심 + +2. 시간복잡도 : O(N^2) + +3. 자료구조/알고리즘 : 완전탐색 + + */ + + +class Solution { + public int[] maxProductPair(int[] nums, int target) { + // 조건을 만족하는 모든 pair중 nums[i] * nums[j]이 가장 큰 값 + // 없으면 [-1, -1] + + int[] ans = {-1, -1}; + int maxVal = Integer.MIN_VALUE; + + for(int i=0; i maxVal) { + maxVal = jVal*iVal; + + if(jVal>iVal) { + ans[0] = j; + ans[1] = i; + } + else { + ans[0] = i; + ans[1] = j; + } + } + } + } + + return ans; + } +} \ No newline at end of file