Given an array nums which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these m subarrays. Example 1: Input: nums = [7,2,5,10,8], m = 2 Output: 18 Explanation: There are four ways to split nums into two subarrays. The best way is to split it into [7,2,5] and [10,8], where the..
Java로 구현한 합병 정렬입니다. 배열을 반으로 나눠서 오른쪽이 왼쪽의 숫자보다 작으면 이동시키는 것을 반복합니다. class MergeSort { void mergesort(int[] array) { int[] helper = new int[array.length]; mergesort(array, helper, 0, array.length - 1); } void mergesort(int[] array, int[] helper, int low, int high) { if (low < high) { int middle = (low + high) / 2; mergesort(array, helper, low, middle); mergesort(array, helper, middle + 1, high); me..
최소값을 상수시간에 리턴하는 stack만들기. stack을 만들면서 간단히 해당 element의 상태일때 최소값을 기억해놨다가 리턴해주면 된다. Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the MinStack class: MinStack() initializes the stack object. void push(val) pushes the element val onto the stack. void pop() removes the element on the top of the stack. int top() gets the top element of the ..
쿠팡에서 설계 문제로 나온 LRU Cache. 핵심 포인트는 HashMap과 LinkedList를 동시에 유지하는 것. Design a data structure that follows the constraints of a Least Recently Used (LRU) cache. Implement the LRUCache class: LRUCache(int capacity) Initialize the LRU cache with positive size capacity. int get(int key) Return the value of the key if the key exists, otherwise return -1. void put(int key, int value) Update the value of..
쿠팡 문제로도 유명한 3SUM이다. Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets. Example 1: Input: nums = [-1,0,1,2,-1,-4] Output: [[-1,-1,2],[-1,0,1]] Example 2: Input: nums = [] Output: [] Example 3: Input: nums = [0] Output: [] Const..
Map charMap2 = new HashMap(); charMap2 = charMap.entrySet().stream() .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, // key가 충돌할때 어떤 key를 선택할지 LinkedHashMap::new)); // LinkedHashMap으로 생성해야 순서가 유지됨
Java HashTable 을 구현해 보았다. Key 충돌 알고리즘은 Chaining 리스트를 통해서 해결했다. package com.study; import java.util.LinkedList; class HashTable { LinkedList[] data; public HashTable(int size) { this.data = new LinkedList[size]; } int getHashCode(String key) { int hashCode = 0; for(char c : key.toCharArray()) { hashCode += c; } return hashCode; } int convertToIndex(int hashCode) { return hashCode % data.length; }..
Java 8 설치Java 8 설치 이유 : Spring 연동 gradle 버전은 Java 9를 찾지 못한다. Apache Tomcat 8.5 다운로드안정버전인 8.5를 다운로드후 적절한 위치에 압축을 풀어놓자. 프로젝트 생성(Spring Initializr)[New Project] - [Spring initializr] 를 선택하여 프로젝트 생성을 시작한다. 이때, 자바 버전을 1.8 정도로 선택하자. Artifact에 프로젝트 명을 입력하고 Type에서 [Gradle Project]를 선택, Packaging에서는 [War]를 선택한다. 프로젝트 설정에서 다음과 같이 선택한다. (DB는 추후에 설정하고, Web과 REST API만 사용하게 설정)WebThymeleaf - 이것을 선택한 이유는 Sprin..
- Total
- Today
- Yesterday