HashMap
-
Dictionary - 가장 긴 연속된 수열알고리즘 2023. 12. 3. 19:58
수열 nums의 원소로 만들 수 있는 가장 긴 연속된 수열의 크기를 구하시오. input: nums = [100, 4, 200, 1, 3, 2], output: 4 input: nums=[0, 3, 7, 2, 5, 8, 4, 6, 0, 1], output: 9 import java.util.HashMap; public class MostLongSeq { public static int returnNum(int[] nums) { HashMap map = new HashMap(); for(int i : nums) { map.put(i, ""); } int max = 0; for(int i=0; i
-
딕셔너리알고리즘 2023. 12. 3. 19:17
nums의 두 원소를 더해 target을 만들 수 있으면 True, 없으면 False return. input: nums = {4,1,9,7,5,3,16}, target: 14, output: True input: nums = {2,1,5,7}, target: 4, output: False input: nums = {2,2,3}, target: 4, output: True 조건: 같은 원소는 중복으로 더할 수 없다. import java.util.HashMap; public class DictionaryTesg { public static boolean dic(int[] nums, int target) { HashMap map = new HashMap(); for(int i: nums) { map.put..