随笔分类 -  算法

摘要:https://leetcode-cn.com/problems/fu-za-lian-biao-de-fu-zhi-lcof/ /* struct RandomListNode { int label; struct RandomListNode *next, *random; RandomLis 阅读全文
posted @ 2021-05-14 11:15 米开朗菠萝 阅读(27) 评论(0) 推荐(0)
摘要:解题思路: 代码: class Solution: def myPow(self, x: float, n: int) -> float: if x == 0: return 0 res = 1 if n < 0: x, n = 1 / x, -n while n: if n & 1: res *= 阅读全文
posted @ 2021-04-28 09:02 米开朗菠萝 阅读(43) 评论(0) 推荐(0)
摘要:Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warme 阅读全文
posted @ 2020-05-06 14:36 米开朗菠萝 阅读(149) 评论(0) 推荐(0)
摘要:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. 阅读全文
posted @ 2020-03-05 17:14 米开朗菠萝 阅读(126) 评论(0) 推荐(0)
摘要:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any p 阅读全文
posted @ 2020-03-05 13:59 米开朗菠萝 阅读(117) 评论(0) 推荐(0)
摘要:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Input: "babad" Output: 阅读全文
posted @ 2020-03-05 11:41 米开朗菠萝 阅读(93) 评论(0) 推荐(0)
摘要:Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 # Definition for a binary tree node. # class TreeNod 阅读全文
posted @ 2020-03-01 16:02 米开朗菠萝 阅读(74) 评论(0) 推荐(0)
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. For example, 阅读全文
posted @ 2020-03-01 11:26 米开朗菠萝 阅读(133) 评论(0) 推荐(0)
摘要:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree [3 阅读全文
posted @ 2020-03-01 10:23 米开朗菠萝 阅读(136) 评论(0) 推荐(0)
摘要:"""解题思路:1.荷兰分区问题,我们把数组分成四类:red, white, 未分类, blue。初始的时候都在未分类组里,只要白色指针小于蓝色指针,我们遍历数组2.当白色指针是是红色的时候nums[white]==0,我们交换红色指针,并且两个指针同时+13.当白色指针是白色的时候,位置在正确位置 阅读全文
posted @ 2020-02-28 09:30 米开朗菠萝 阅读(148) 评论(0) 推荐(0)
摘要:“”“解题思路:遍历数组,每次遍历记录数组最小值,并且用计算当前值和最小值之差为利润,记录最大的利润”“”class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ 阅读全文
posted @ 2020-02-28 08:18 米开朗菠萝 阅读(114) 评论(0) 推荐(0)
摘要:# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None # 递归,中序遍 阅读全文
posted @ 2020-02-18 11:13 米开朗菠萝 阅读(88) 评论(0) 推荐(0)
摘要:#用二分查找法class Solution(object): def searchRange(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ first = 0 last = 阅读全文
posted @ 2020-02-11 17:13 米开朗菠萝 阅读(104) 评论(0) 推荐(0)
摘要:# 递归方法解决class Solution(object): def letterCombinations(self, digits): """ :type digits: str :rtype: List[str] """ d = {"2":"abc", "3":"def", "4":"ghi" 阅读全文
posted @ 2020-02-11 16:16 米开朗菠萝 阅读(89) 评论(0) 推荐(0)
摘要:class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ stack = [] #存放符号 d = {"]": "[", ")":"(", "}":"{"} “”“ 判断符号是否是结束符号,如果是, 阅读全文
posted @ 2020-02-11 13:53 米开朗菠萝 阅读(73) 评论(0) 推荐(0)
摘要:class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ usedchar = {} #存储无重复得字符 max_length = start = 0 #初始化最长字 阅读全文
posted @ 2020-02-10 20:04 米开朗菠萝 阅读(107) 评论(0) 推荐(0)
摘要:一、冒泡排序 冒泡排序动图演示 二、选择排序 动态图 三、插入排序 从第一个元素开始,该元素可以认为已经被排序; 取出下一个元素,在已经排序的元素序列中从后向前扫描; 如果该元素(已排序)大于新元素,将该元素移到下一位置; 重复步骤3,直到找到已排序的元素小于或者等于新元素的位置; 将新元素插入到该 阅读全文
posted @ 2019-04-28 23:31 米开朗菠萝 阅读(231) 评论(0) 推荐(0)
摘要:Given a linked list, swap every two adjacent nodes and return its head. Example: Note: Your algorithm should use only constant extra space. You may no 阅读全文
posted @ 2019-01-30 15:36 米开朗菠萝 阅读(127) 评论(0) 推荐(0)
摘要:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the 阅读全文
posted @ 2019-01-30 14:48 米开朗菠萝 阅读(90) 评论(0) 推荐(0)
摘要:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You may not modify the values in the list's nodes, only nodes its 阅读全文
posted @ 2019-01-30 08:40 米开朗菠萝 阅读(96) 评论(0) 推荐(0)