LeetCode

Algorithm/Python

[python/leetcode]network delay time/dijkstra/heapq

💬 문제 You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the time it takes for a signal to travel from source to target. We will send a signal from a given node k. Return the time it takes for all the n nodes to receive the signal. If it i..

Algorithm/Python

[python/leetcode]course schedule/tree/dfs

문제 There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai. For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1. Return true if you can finish all courses. Otherwise, return ..

Algorithm/Python

[LeetCode - Top Interview Questions(Easy, Python3)]Strings

1. Reverse String class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ s.reverse() in-place라 reverse()를 사용했지만, slicing(s[:] = s[::-1])이 조금 더 빠르다. 2. Reverse Integer class Solution: def reverse(self, x: int) -> int: if x == 0: return 0 result = int(str(abs(x))[::-1]) # 32-bit 정수 범위를 넘은 경우 0으로 처리 if result2**31-1: return 0 # x가 양..

Algorithm/Python

[LeetCode - Top Interview Questions(Easy, Python3)]Array

리트코드 Top Interview Questions 챕터 1 Array 전체 Python3 풀이 Remove Duplicates from Sorted Array class Solution: def removeDuplicates(self, nums: List[int]) -> int: i = 0 while i int: profit = 0 for i in range(len(prices)-1): if prices[i] None: """ Do not return anything, modify nums in-place instead. """ while k!=0: nums.insert(0, nums.pop()) k -= 1 k번만큼 nums 배열 맨 뒤의 원소를 맨 앞으로 이동시키는 문제다. Contains Dupl..

박한결
'LeetCode' 태그의 글 목록 (2 Page)