java/javaAlgorithm(16)
-
[Leetcode]3146. Permutation Difference between Two Strings
1. problem :https://leetcode.com/problems/permutation-difference-between-two-strings/description/ 2. solution 1 :public class Solution { public int findPermutationDifference(String s, String t) { int count = 0; HashMap hashMap = new HashMap(); for (int i = 0; i
2024.07.30 -
[Leetcode]1679. Max Number of K-Sum Pairs(x)
1. problem : https://leetcode.com/problems/max-number-of-k-sum-pairs/?envType=study-plan-v2&envId=leetcode-75 2. solution 1 :public class Solution { public int maxOperations(int[] nums,int k) { int count = 0; HashMap hashMap = new HashMap(); for (int num : nums) { int target = k - num; if (hashMap.getOrDefault(target, 0) > 0) { count++..
2024.07.30 -
[Leetcode]1111. Maximum Nesting Depth of Two Valid(x)
1. problem :https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings/ 2. solution 1 :class Solution { public int[] maxDepthAfterSplit(String seq) { int n = seq.length () ,s1 =0, s2 = 0; int[] ans = new int [n] ; for ( int i = 0 ; i s2){ s1 -- ; ans [i] = 0 ; } else { ..
2024.07.30 -
[Leetcode]11. Container With Most Water
1. problem : https://leetcode.com/problems/container-with-most-water/?envType=study-plan-v2&envId=leetcode-75 2. solution 1 :class Solution { public int maxArea(int[] height) { int n = height.length; int i = 0; int j = n - 1; int maxWater = 0; while (i 이 문제는 큰 스틱은 그대로 두고, 작은 스틱을 옮기면서 최댓값은 갱신하는 문제다. 사실, 발상자체가 이해가 되지 않는다. 왜? 작은 스틱을 옮겨야 하는가? 이게 모든 경우에 적용할 수 있는가..
2024.07.29 -
[Leetcode]654. Maximum Binary Tree
1. problem :https://leetcode.com/problems/maximum-binary-tree/ 2. solution 1 : class Solution { public TreeNode constructMaximumBinaryTree(int[] nums) { if (nums.length == 0) { return null; } int maxNumIndex = 0; for (int i = 1; i recursion을 이용한 풀이다. 사실 제일 간단한 풀이가 아닐까 싶다. 3. solution 2 :import java.util.Stack;public class Solution { public TreeNode c..
2024.07.29 -
[Leetcode]2942. Find Words Containing Character
1. problem : https://leetcode.com/problems/find-words-containing-character/ 2. solution 1 : class Solution { public List findWordsContaining(String[] words, char x) { List result = new ArrayList(); for (int i = 0; i 이 방법은 import java.util.List;를 불러와서 List result = new ArrayList ();를 활용해서, 문제를 풀었다. 기존의 int [] result = new int []로 하면 동적배열이 힘들어져, 이 방법을 쓰는 것이다.
2024.07.28