![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 93
计算机基本数据结构和算法。主要使用Python语言解决leetcode上的题目
hope_worker
这个作者很懒,什么都没留下…
展开
-
leetcode 122. Best Time to Buy and Sell Stock II
Question Say you have an array prices for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multip原创 2020-10-10 09:02:45 · 134 阅读 · 0 评论 -
leetcode 463. Island Perimeter
class Solution: def islandPerimeter(self, grid: List[List[int]]) -> int: """ grid = [[0,1,0,0], [1,1,1,0], [0,1,0,0], [1,1,0,0]] """ ...原创 2020-09-02 09:01:42 · 93 阅读 · 0 评论 -
自动为 Gatsby网站中的 Markdown 页面添加 sidebar
我想在Gatsby网站上创建Markdown页面时自动添加侧边栏。 有一个 starter “ gatsby-gitbook-starter” 可以支持markdown文件的侧边栏,但仅支持1级。 我希望能够支持更多级别。原创 2020-08-18 17:51:31 · 371 阅读 · 0 评论 -
binary search - leetcode 33. Search in Rotated Sorted Array
1. question Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). You are given a target value to search. If found in the array return its index, otherwise ret原创 2020-08-12 09:43:38 · 126 阅读 · 0 评论 -
quick sort
""" step 1 : maintain the following structure a[l] ...... ,,,,,, < a[l] > a[l] j i step 2: in the end, swap(l, j), return j . .....a[l] ,,,,,, < a[l] > a[l] j i For examp原创 2020-07-15 08:42:13 · 122 阅读 · 0 评论 -
Python slice notation [:] - leetcode 189. Rotate Array
1. a[start:stop:step] q = "12345" w = q[0:2:1] # [0, 2) print(f"w: {w}") # w: 12 w = q[::-1] # if step is negative, reverse traverse print(f"w's type: {type(w)} w: {w}") # w's type: <class 'str'> w: 54321 w = q[::-2] print(f"w: {w}") # w: 531 2.原创 2020-06-29 15:11:39 · 129 阅读 · 0 评论 -
slide window & +Counter() : leetcode 438. Find All Anagrams in a String
def findAnagrams_leetcode(self, s: str, p: str) -> List[int]: if len(s) < len(p): return [] p_chars = Counter(p) i = 0 j = len(p) window = Counter(s[i:j]) results = [] while j &...原创 2020-06-12 15:21:29 · 168 阅读 · 0 评论 -
subsets : zero left padding : leetcode 78
leetcode 78 求解序列的所有子集。 例如: [1, 2, 3]. 所有子集为:[ [ ], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3] ] 其中一种解题思路为: 使用2进制来表示,组合中是否包含某个元素。 例如 001–> [3], 101–>[1, 3], 111–>[1, 2, 3] 因此只有列出 [0, 2n) 的2进制表示,就可以求出所有的子集。 求解2进制表示时,有一个“zero left padd原创 2020-06-02 07:37:11 · 105 阅读 · 0 评论 -
backtrace&usage of slice notation[:] - leetcode 77. Combinations
def combine(self, n: int, k: int) -> List[List[int]]: """ Input: n = 4, k = 2 Output: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] :param n:...原创 2020-05-26 09:07:52 · 162 阅读 · 1 评论 -
build tree & sum path (usage of list[0]) - 404. Sum of Left Leaves
from collections import deque class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def printTreeCore(self, root, preorder=True): if not原创 2020-05-22 06:37:11 · 140 阅读 · 2 评论