전체 글161 LSCS Largest Sum of contiguous Subarray 정수 배열의 연속 부분 배열의 합 중 최댓값 구하기 public class Solution { public int LSCS(int[] arr) { for(int i=0; iLS) LS=temp; if(temp 2022. 10. 18. Binary Search Binary Search iteration way //java Binary search //iteration way public class Solution { public int binarySearch(int[] arr, int target) { int low=0; int high=arr.length-1; while(low 2022. 10. 13. Heap Sort import java.util.*; public class Solution { public int[] heapSort(int[] arr) { //우선순위 큐를 선언하여 heap을 구현 가능 PriorityQueue heap = new PriorityQueue(); //java에서는 기본이 minheap //maxheap : PriorityQueue heap = new PriorityQueue(Collections.reverseOrder()); for(int el : arr) heap.add(el); for(int i=0; i 2022. 10. 11. Merge Sort import java.util.*; public class Solution { public int[] mergeSort(int[] arr) { // TODO : //재귀로 구현 if(arr.length==1) return arr; int half=arr.length/2; int arr1[]=Arrays.copyOf(arr, half); int arr2[]=Arrays.copyOfRange(arr, half, arr.length); arr1=mergeSort(arr1); arr2=mergeSort(arr2); int j=0, k=0; for(int i=0; i 2022. 10. 11. 이전 1 ··· 31 32 33 34 35 36 37 ··· 41 다음