전체 글(334)
-
[Leetcode]217. Contains Duplicate
1. problem : https://leetcode.com/problems/contains-duplicate/ 2. solution 1 :public class Solution { public boolean containsDuplicate(int[] nums) { HashMap hashMap = new HashMap(); for (int i=0; i HashMap을 써서, 값이 들어있다면, true 반환, 없다면 추가, 루프가 정상적으로 끝난다면, false 반환
2024.07.30 -
[Leetcode]1456. Maximum Number of Vowels in a Substring of Given Length
1. problem :https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/ 2. solution 1 :class Solution: def maxVowels(self, s: str, k: int) -> int: vowels = set("aeiou") current_count = 0 max_count = 0 # initialize window for i in range(k): if s[i] in vowels: current_count += 1 max_count ..
2024.07.30 -
[Leetcode]643. Maximum Average Subarray I
1. problem : https://leetcode.com/problems/maximum-average-subarray-i/description/?envType=study-plan-v2&envId=leetcode-75 2. solution 1 :class Solution: def findMaxAverage(self, nums: List[int], k: int) -> float: temp_sum = sum(nums[:k]) max_sum = temp_sum for i in range(1,len(nums)-k+1): temp_sum = temp_sum - nums[i-1] + nums[i+k-1] if temp_sum ..
2024.07.30 -
[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