본문 바로가기

728x90
반응형

Major-

(865)
[LeetCode- Ch3. 배열] 6. 누락된 범위 # (+ 삼항 연산자) https://www.lintcode.com/problem/641/ LintCode 炼码 www.lintcode.com 1. 예외처리 필수 2. 범위설정이 중요하다. -> 처음 / 중간 /끝 //배열이 존재하지 않을 때 list.add(makeRange(lower, upper)); //처음 list.add(makeRange(lower,nums[0]-1)); //중간 list.add(makeRange(nums[i]+1, nums[i+1]-1)); //끝 list.add(makeRange(nums[n-1]+1,upper)); 3. 삼항 연산자 사용한 범위 생성 메서드 작성 private static String makeRange(int start, int end){ //return start==end ? I..
[LeetCode- Ch3. 배열] 5. 빗물 담기 # [+ 분할과 정복] https://leetcode.com/problems/trapping-rain-water/ Trapping Rain Water - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 해결 [Divide & Conquer] 1. 물이 차는 영역 결정 -> Math.min -> 왼쪽벽과 오른쪽 벽의 값의 차이 만큼 물이 찬다. 2. 밑의 높이만큼 빼야한다. -> Math.min -밑의 높이 3. 필요한 자료구조 left[] : 왼쪽 벽 최대 높이 배열 right[]..
[LeetCode- Ch3. 배열] 4. 그룹 아나그램 (+ computeIfAbsent() ) https://leetcode.com/problems/group-anagrams/ Group Anagrams - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Map 자료구조를 만들어서 해결 1. toCharArray()후 정렬을 수행해 유일한 키로 만든다 2. 정렬한 키의 리스트가 존재하면, 존재하지 않으면 케이스분류해서 작성 1. 자바8 람다식 이용 : computeIfAbsent() 2. List 존재하면, 존재하지 않으면 분류 import java.uti..
[LeetCode- Ch3. 배열] 3. 부분배열 최댓값 (+ DP) https://leetcode.com/problems/maximum-subarray/submissions/ Maximum Subarray - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. DFS 이용 : 타임리밋 발생 2. DP 이용 : 현재까지 가장 큰 값 저장하는 배열 -> dy[0] : 배열의 첫번째 값으로 초기화 -> 반복은 nums[1]부터 시작해, 이전 배열의 값을 더한 값과 현재 배열 값 중 Max값 선택 1. DFS 이용 class Solut..
[LeetCode- Ch3. 배열] 2. 일일 온도 # (+ arr+stack) https://leetcode.com/problems/daily-temperatures/submissions/ Daily Temperatures - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 이중 For문 이용 : 타임리밋 발생 2. for+while문: 타임리밋 발생 : 더 높은 온도 찾을 때 까지 while문으로 반복 3. 스택이용 : 스택에 배열의 인덱스를 넣고, 배열을 돌면서 인덱스간 차이를 이용 1. 이중 for문 이용 import java.u..
[LeetCode- Ch3. 배열] 1. 두개 합 (+ Map) https://leetcode.com/problems/two-sum/submissions/ Two Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 조건을 만족하는 단 하나의 값만 존재 -> 이중 For문 class Solution { static int[] arr; public int[] twoSum(int[] nums, int target) { //두개 합 //정수 배열과 정수 arr=nums; int n=nums.length; int[] ans..
[LeetCode- Ch.2 정렬 & 검색] 7. 로그 파일의 데이터 재정렬 ## (+ Comparator 오버라이딩) https://leetcode.com/problems/reorder-data-in-log-files/submissions/ Reorder Data in Log Files - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. result 문자열 마지막에 " "공백 지우기 2. 문자 로그 정렬시, 문자 로그가 모두 같으면 개수가 적은 것 오름차순 정렬 import java.util.*; class Solution { public String[] reorderLog..
[LeetCode- Ch.2 정렬 & 검색] 6. interval 병합 ## (+ List to Arrays) https://leetcode.com/problems/merge-intervals/submissions/ Merge Intervals - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 케이스 분류 1. 시작이 끝보다 클 때, 시작이 끝과 같을 때, 끝이 시작보다 크고도, 끝보다 작을 때 2. 처음에는 추가하지 않고 그 다음부터 추가하는데, 마지막은 반복문에서 추가하지 못하므로 따로 추가 import java.util.*; class Solution { publi..

728x90
반응형