목록알고리즘 문제풀이/Leetcode (22)
취미가 좋다
https://leetcode.com/problems/next-permutation/ Next Permutation - 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 Solution class Solution: def nextPermutation(self, nums): temp = [] for idx in range(len(nums)-1, 0, -1): if nums[idx] nums[idx-1]: temp[i], nums[idx-1] = nums[idx-1],..
https://leetcode.com/problems/search-a-2d-matrix-ii/ Search a 2D Matrix II - 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 Solution class Solution: def searchMatrix(self, matrix, target): row, col = 0, len(matrix[0])-1 while row = 0: if matrix[row][col] < t..
https://leetcode.com/problems/sliding-window-maximum/submissions/ Sliding Window Maximum - 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 Solution import heapq from collections import defaultdict class Solution: def maxSlidingWindow(self, nums, k): ans = [max(nums[:k])] pq = [] ou..
https://leetcode.com/problems/product-of-array-except-self/ Product of Array Except Self - 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 Solution class Solution: def productExceptSelf(self, nums): if nums.count(0) > 1: return [0]*len(nums) idx = -1 total = 1 for i, n in enumerate..
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ Lowest Common Ancestor of a Binary Tree - 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 Solution class Solution: def __init__(self): self.ans = None def lowestCommonAncestor(self, root, p, q) : ans = None def ..
https://leetcode.com/problems/kth-smallest-element-in-a-bst/ Kth Smallest Element in a BST - 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 Solution class Solution: def kthSmallest(self, root, k): def rank(node, ans): if node.left and rank(node.left, ans): return True ans.append(n..