본문 바로가기

반응형

Java/Java 알고리즘 LeetCode

(60)
[LeetCode- Part. 3] 2. 소행성 충돌 https://leetcode.com/problems/asteroid-collision/ Asteroid Collision - 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. 둘이 만날 경우 조건 분기 (1) 같을 경우 둘다 파괴 (2) 절댓값이 큰 경우가 남는다. class Solution { public int[] asteroidCollision(int[] arr) { Stack stack = new Stack(..
[LeetCode- Part. 3] 1. 회문 깨기 # (+toCharArray, valueOf) https://leetcode.com/problems/break-a-palindrome/ Break a Palindrome - 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 사전적으로 가장 작은 변화를 통해 팰린드롬을 깬다. -> 팰린드롬을 결정하는 부분 전까지 a가 아닌 문자를 a로 바꾼다. ->단, 모두 a인 경우에는 마지막 자리를 b로 바꾼다. +) 세련된 풀이 class Solution { public String breakPalindrome(String..
[LeetCode- Part. 2] 5. 음식을 구하기위한 최단 경로 (+BFS) package Part2.Q6; import java.util.LinkedList; import java.util.Queue; public class Solution { public static void main(String[] args) { char[][] grid = { { 'X', 'X', 'O', 'O', 'O', 'X' }, { 'X', 'I', 'O', 'X', 'O', 'X' }, { 'X', 'O', 'O', 'X', 'F', 'X' }, { 'X', 'X', 'X', 'X', 'X', 'X' } }; System.out.println(solve(grid)); } static int n,m; static boolean [][] check; public static int solve(char..
[LeetCode- Part. 2] 4. 가장 긴 회문 부분 문자열 (+ 2차원 DP) # https://leetcode.com/problems/longest-palindromic-substring/submissions/ Longest Palindromic Substring - 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 { public String longestPalindrome(String s) { int cnt=Integer.MIN_VALUE; String answer="..
[LeetCode- Part. 2] 3. 두 단어 이상 연결된 단어 # https://leetcode.com/problems/concatenated-words/submissions/ Concatenated Words - 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 참고 자료 https://and-some.tistory.com/928 [LeetCode- Part. 1] 5. 단어 나누기 # https://leetcode.com/problems/word-break/ Word Break - LeetCode Level up your co..
[LeetCode- Part. 2] 2. 트럭의 실을 수 있는 최대단위 https://leetcode.com/problems/maximum-units-on-a-truck/ Maximum Units on a Truck - 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 트럭 한 대에 상자를 넣는 2차원 배열 boxTypes[i] = [numberOfBoxes, numberOfUnitsPerBox] 트럭에 실을 수 있는 상자 truckSize가 주어지면 truckSize를 초과하지 않는 한 트럭에 넣을 상자를 선택해, 트럭에 실을 수있는..
[LeetCode- Part. 2] 1. 원 안에서 로봇 # (+ toCharArray) https://leetcode.com/problems/robot-bounded-in-circle/ Robot Bounded In Circle - 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 로봇이 원을 그리는지 확인 로봇은 처음(0, 0) 북쪽을 향한다. 로봇은 세 가지 명령 수행 가능 "G": 1 단위 직진 "L": 왼쪽으로 90도 회전 "R": 오른쪽으로 90도 회전 로봇은 주어짂 것을 순서대로 수행하면서 무한반복 로봇이 평면에 원을 그리는 경우 true를..
[LeetCode- Part. 1] 7. 금광 찾기 # https://leetcode.com/problems/path-with-maximum-gold/submissions/ Path with Maximum Gold - 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. 같은 셀을 두 번 이상 방문 할 수 없다 4. 0이 있는 셀은 방문할 수 없다 5. 모든 위치에서 금 수집을 시작하고 중지 ..

반응형