리트코드 130 Surrounded Regions (파이썬)
2022. 10. 23. 15:50
리트코드
https://leetcode.com/problems/surrounded-regions/submissions/ Surrounded Regions - 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 풀이 및 해설(주석) class Solution(object): def solve(self, board): N, M = len(board), len(board[0]) def dfs(r, c): if r < 0 or c < 0 or r == N or c == M or bo..
리트코드 778 Swim in Rising Water (파이썬)
2022. 10. 10. 20:10
리트코드
https://leetcode.com/problems/swim-in-rising-water/ Swim in Rising 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 (0, 0)에서 (N-1, N-1)로 가는 최단 거리를 찾는 전형적인 다익스트라 알고리즘 문제 풀이 import heapq class Solution(object): def swimInWater(self, grid): N = len(grid) visit = set() minH = [[..
리트코드 1584 Min Cost to Connect All Points (파이썬)
2022. 10. 10. 19:33
리트코드
https://leetcode.com/problems/min-cost-to-connect-all-points/ Min Cost to Connect All Points - 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 전형적인 MST문제이다. 풀이 및 해설(주석) import heapq class Solution(object): def minCostConnectPoints(self, points): N = len(points) adj = { i:[] for i i..
리트코드 684 Redundant Connection (파이썬)
2022. 10. 9. 16:05
리트코드
https://leetcode.com/problems/redundant-connection/ Redundant Connection - 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 아이디어 엣지의 정보가 주어지므로 엣지를 순차적으로 순회하며 연결시켜 그래프를 만든다. 그래프를 만들며 싸이클이 생기는 엣지의 정보를 발견하면 그 엣지를 return한다. 풀이 및 해설(주석) class Solution(object): def findRedundantConnection..
리트코드 79 Word Search (파이썬)
2022. 10. 9. 14:57
리트코드
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 풀이 및 해설 from collections import defaultdict class Solution(object): def exist(self, board, word): N, M = len(board), len(board[0]) # dfs탐색 하기 전의 사전 작업 단어가 충분하지 않다면, 바로 False를 re..
리트코드 417 Pacific Atlantic Water Flow (파이썬)
2022. 10. 9. 14:20
리트코드
https://leetcode.com/problems/pacific-atlantic-water-flow/ Pacific Atlantic Water Flow - 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 각 좌표들이 갈 수 있는 경우는 인접한 좌표가 자기보다 낮은 수를 가지고 있어야 한다. 그렇게 이동하다 맨 왼쪽 또는 제일 위, 맨 오른쪽 또는 제일 아래에 도달하면, 두 바다를 갈 수 있다. 풀이 및 해설(주석) class Solution(object): d..
리트코드 127 Word Ladder (파이썬)
2022. 10. 8. 22:32
리트코드
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 풀이 및 해설(주석) import collections class Solution(object): def ladderLength(self, beginWord, endWord, wordList): if endWord not in wordList: return 0 # {*ot:[hot, dot], h*t:[hot, hi..
리트코드 134 Gas Station (파이썬)
2022. 10. 2. 16:19
리트코드
https://leetcode.com/problems/gas-station/ Gas Station - 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 풀이 class Solution(object): def canCompleteCircuit(self, gas, cost): # 만약 gas의 총 합이 cost의 총 합보다 작다는 것은, 어느 칸에서든 한 바퀴를 못돈다는 것이다. if sum(gas) < sum(cost): return -1 # start는 인덱스 번호..