상기 두 함수는 같은 역할을 함!for (int i = 0; i public class CombinationExample { public static int countZeroSumCombinations(int[] numbers) { return combination(numbers, 0, 4, 0); } private static int combination(int[] numbers, int start, int r, int sum) { // 기저 조건: 4개의 숫자를 모두 선택했을 때 if (r == 0) { return sum == 0 ? 1 : 0; // 합이 0이면 1을 반환, 아니면 0 반환 } int..
public static int[] solution(int k, int[] score) { int[] answer = new int[score.length]; //PriorityQueue의 우선순위 컬렉션을 지정해주지 않으면, 오름차순으로 지정됨 PriorityQueue priority = new PriorityQueue(); //(Collections.reverseOrder())라고 우선순위를 지정해주면 내림차순으로 지정됨 for(int i = 0 ; i >> " + i +">>>>" + priority.toString()); if(priority.size() > k) { //가장 작은 값을 반환하고 삭제함 ..
123456HashMapString, Integer> playersMap = new HashMapString, Integer>(); ListString> keySet = new ArrayList>(playersMap.keySet()); //방법 1 keySet.sort((o1,o2) -> playersMap.get(o1).compareTo(playersMap.get(o2))); //방법 2 Collections.sort(keySet, (o1,o2) -> playersMap.get(o1).compareTo(playersMap.get(o2)));cs
1234567891011121314151617181920212223242526272829303132333435import java.util.*;class Solution { public int[][] solution(int[][] data, String ext, int val_ext, String sort_by) { List indexList = Arrays.asList("code","date","maximum","remain"); int extIdx = indexList.indexOf(ext); int sortIdx = indexList.indexOf(sort_by); // 수기로 오름차순 정렬하는 방법 Listint[..
인스턴스의 정의자바에서 "인스턴스"란 클래스의 구조를 바탕으로 생성된 실제 객체를 의미합니다. 좀 더 구체적으로 설명하자면, 클래스는 객체의 청사진(설계도)이며, 이 설계도를 기반으로 메모리에 생성된 실체가 바로 인스턴스입니다. 이 인스턴스를 통해 클래스에 정의된 속성과 메서드를 사용할 수 있게 됩니다. 메서드 영역(Method Area), 인스턴스 영역(Instance Area, Heap), 스택 영역(Stack Area) 차이자바에서 메서드 영역(Method Area), 인스턴스 영역(Instance Area, Heap), 그리고 스택 영역(Stack Area)은 모두 JVM 메모리 구조의 중요한 구성 요소로, 각각의 역할과 특징이 다릅니다. 이들을 비교하면 다음과 같습니다.메서드 영역(Method..