본문 바로가기

728x90
반응형

Major-

(865)
[LeetCode- Ch8. 동적계획법] 3. 동전 교환 # https://leetcode.com/problems/coin-change/submissions/ Coin Change - 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/662 [Ch.10 - DP] 05. 동전교환 [+냅색 알고리즘] 5. 동전교환(냅색 알고리즘) 냅색 알고리즘 : 담을 수 있는 무게가 정해진 백팩에 가장 비싼 금액의 물건으로 채우는 알고리즘 설명 다음과 같이 여러 ..
[LeetCode- Ch8. 동적계획법] 2. 계단 오르기 # https://leetcode.com/problems/climbing-stairs/ Climbing Stairs - 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칸씩 오를 수 있다. 0칸 -> 경우의 수 0 1칸 -> 경우의 수 1 2칸 -> 경우의 수 2 .... n칸 -> n-1칸의 경우의 수 + n-2칸의 경우의 수 class Solution { public int climbStairs(int n) { //계단은 1칸이나 2칸씩 오를 수 있다...
[LeetCode- Ch8. 동적계획법] 1. 유일한 경로 https://leetcode.com/problems/unique-paths/ Unique Paths - 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)부터 (n,m)까지 유일한 경로의 개수를 구한다. 문제 해결 순서 1. 한번에 이동가능한 경로를 이동경로 배열에 추가 2. 그 외의 경로 두 경로의 합으로 추가 class Solution { public int uniquePaths(int m, int n) { int[][] arr = new ..
[LeetCode- Ch7. DFS & BFS] 7. 구슬 미로 https://www.lintcode.com/problem/787/ LintCode 炼码 www.lintcode.com BFS 기본 방향 설정 & 배열 사이즈 변수 설정 맞는 조건 탐색 큐 생성 조건 체크해서 큐 넣기 마이너스 좌표 체크 m*n 범위 체크 grid[x][y]값 체크 문제 조건 1. 구슬은 벽이 없으면 한 방향으로 쭉 이동한다. 2. 이동한 다음에는 다른 방향으로 이동 가능하다. 3. 시작지점에서 목적지점까지 갈 수 있는지 여부 리턴 문제 풀이 순서 - BFS 1. Queue에서 poll 한후 2. 4방향으로 체크시작 3. 공식: 조건체크 부분 수행 4. (3,4)까지 도착한후 에러 체크 한다. While문에 서 올린 좌표를 –로 원상복귀 visited[x][y]==true인지 체크 후 방..
[LeetCode- Ch7. DFS & BFS] 6. 유효하지 않은 괄호 제거 https://leetcode.com/problems/remove-invalid-parentheses/ Remove Invalid Parentheses - 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. 유효하지 않는 괄호는 제거한다. 문제 해결 순서 Queue에 저장 케이스별로 유효성 체크 쌍으로 존재하는지 체크해, 해당하는 문자열을 새로운 큐에 저장 유효한 괄호 확인..
[LeetCode- Ch7. DFS & BFS] 5. 단어 검색 # https://leetcode.com/problems/word-search/ Word Search - 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. 원하는 단어를 배열에서 한줄로 이어진 상태로 찾으면 true 리턴 2. DFS를 이용 : 좌표, visited, word 1. 타임리밋 발생 class Point{ public int x,y; Point(int x, int y){ this.x=x; this.y=y; } } class Solution { stat..
[LeetCode- Ch7. DFS & BFS] 4. 단어 사다리 # https://leetcode.com/problems/word-ladder/ Word Ladder - 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. DFS 시도 3. BFS 시도 DFS 시도 class Solution { static int answer=Integer.MAX_VALUE; static int rawnum=97; static List list; static String end; public int ladderLength(String beginW..
[LeetCode- Ch7. DFS & BFS] 3. 섬의 최대 면적 https://leetcode.com/problems/max-area-of-island/submissions/ Max Area of Island - 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. 구한 섬의 개수를 이용해, BFS를 시작할때 1로 시작해 돌면서 한칸씩 추가한다. class Point{ public int x, y; Point(int x, int y){ this.x=x; this.y=y; } } class Soluti..

728x90
반응형