본문 바로가기

반응형

Java/Java 알고리즘 LeetCode

(60)
[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..
[LeetCode- Ch.2 정렬 & 검색] 5. 미팅룸2 - 최소 회의실 개수 ## (+ PriorityQueue) https://www.lintcode.com/problem/919/ LintCode 炼码 www.lintcode.com https://www.acmicpc.net/problem/19598 19598번: 최소 회의실 개수 2개 회의실로 3개 회의를 모두 진행할 수 있다. 예를 들어, 첫번째 회의실에서 첫번째 회의를 진행하고 두번째 회의실에서 두번째 회의와 세번째 회의를 진행하면 된다. 1개 회의실로 3개 회의 www.acmicpc.net 이전 문제와 다르게 시작 시간 기준 오름차순 정렬,시작 시간이 같으면 끝나는 시간 기준 오름차순 -> 반례가 존재하기 때문 import java.util.*; class Main{ public static void main(String args[]) throws Excep..
[LeetCode- Ch.2 정렬 & 검색] 4. 미팅룸 (+ 2차원 배열 정렬) https://www.lintcode.com/problem/920/ LintCode 炼码 www.lintcode.com https://www.acmicpc.net/problem/1931 끝나는 시간 기준 오름차순 정렬, 끝나는 시간이 같으면 시작 시간 기준 오름차순 import java.util.*; class Main{ public static boolean main(String args[]) throws Exception{ Scanner sc = new Scanner(System.in); int N=sc.nextInt(); int[][] arr =new int[N][2]; //시작 시간, 끝나는 시간 for(int i=0;i { if(o1[1] == o2[1]){ return Integer.compa..
[LeetCode- Ch.2 정렬 & 검색] 3. 원점에 가장 가까운 지점 ## (+ Double 정렬, PriorityQueue 정렬) https://leetcode.com/problems/k-closest-points-to-origin/submissions/ K Closest Points to Origin - 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. 제곱근 함수 : Math.sqrt() 2. 제곱 함수 : Math.pow() import java.util.*; class Point{ public double value; public int[] arr; Point(double valu..
[LeetCode- Ch.2 정렬 & 검색] 2. K번째 제일 큰 원소 (+ PriorityQueue) https://leetcode.com/problems/kth-largest-element-in-an-array/submissions/ Kth Largest Element in an Array - 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. 배열 이용 3. PriorityQueue 이용 import java.util.*; class Solution { public int findKthLargest(int[] nums, int k) { Li..
[LeetCode- Ch.2 정렬 & 검색] 1. 제로 이동 (+ allMatch, noneMatch, for-while) https://leetcode.com/problems/move-zeroes/submissions/ Move Zeroes - 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 import java.util.*; class Solution { public int[] moveZeroes(int[] nums) { //정수 배열에서 0이 아닌 값은 순서를 유지하고, 모든 0은 마지막으로 이동 //배열 복사본 만들지 않고 수행 //1.ds int n=nums.length; /..

반응형