自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

caisense的专栏

诗和远方

  • 博客(13)
  • 收藏
  • 关注

原创 132. 分割回文串 II

https://leetcode-cn.com/problems/palindrome-partitioning-ii/comments/回溯(超时):class Solution: def minCut(self, s): """ :type s: str :rtype: int """ self.min...

2019-01-24 22:49:08 214

原创 131. 分割回文串

https://leetcode-cn.com/problems/palindrome-partitioning/submissions/class Solution: def partition(self, s): """ :type s: str :rtype: List[List[str]] """ s..

2019-01-23 12:27:19 128

原创 130. 被围绕的区域

https://leetcode-cn.com/problems/surrounded-regions/comments/两次遍历。第一次先遍历边界,dfs将所有与边界O相连的O置为‘-’。之后再遍历所有,将所有O变为X,所有’-‘变为Oclass Solution: def solve(self, board): """ :type board: Li...

2019-01-22 12:16:13 342

原创 129. 求根到叶子节点数字之和

https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/submissions/# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = ...

2019-01-21 12:54:05 207

原创 128. 最长连续序列

https://leetcode-cn.com/problems/longest-consecutive-sequence/用哈希表存储每个端点值对应连续区间的长度若数已在哈希表中:跳过不做处理若是新数加入:取出其左右相邻数已有的连续区间长度 left 和 right计算当前数的区间长度为:cur_length = left + right + 1根据 cur_length 更新最大长...

2019-01-20 13:52:14 177

原创 433. 最小基因变化

https://leetcode-cn.com/problems/minimum-genetic-mutation/submissions/基本类似127题,bfsimport queueclass Solution: def minMutation(self, start, end, bank): """ :type start: str ...

2019-01-19 17:42:19 468

原创 127. 单词接龙

https://leetcode-cn.com/problems/word-ladder/思路和126差不多,区别在于只用bfs,每次访问一层,用一个map来存储访问过的结点以及与起点的距离,避免重复访问。最后输出map中的终点项即可import queueclass Solution: def ladderLength(self, beginWord, endWord, wordL...

2019-01-18 16:37:24 156

原创 126. 单词接龙 II

https://leetcode-cn.com/problems/word-ladder-ii/submissions/dfs+bfsimport queueclass Solution: def findLadders(self, beginWord, endWord, wordList): """ :type beginWord: str ...

2019-01-17 18:39:12 555

原创 125. 验证回文串

https://leetcode-cn.com/problems/valid-palindrome/comments/class Solution: def isPalindrome(self, s): """ :type s: str :rtype: bool """ #将s过滤,只保留数字和字母,再转为小...

2019-01-08 23:19:44 98

原创 124. 二叉树中的最大路径和

https://leetcode-cn.com/problems/binary-tree-maximum-path-sum/submissions/对于任意一个节点, 如果最大和路径包含该节点, 那么只可能是两种情况:1. 其左右子树中所构成的和路径值较大的那个加上该节点的值后向父节点回溯构成最大路径2. 左右子树都在最大路径中, 加上该节点的值构成了最终的最大路径。# Definiti...

2019-01-08 22:44:27 154

原创 123. 买卖股票的最佳时机 III

https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iii/comments/dp1[i] = max(dp[i-1], prices[i] - minval) 从前往后遍历,表示第1天到第i天之间的最大利润(通过是否在第i天卖出确认);dp2[i] = max(dp[i+1], maxval - prices[i]...

2019-01-06 16:17:14 356

原创 122. 买卖股票的最佳时机 II

https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/submissions/观察知,累加每两个相邻峰谷之间的差价即可class Solution(object): def maxProfit(self, prices): """ :type prices: List[in...

2019-01-04 16:42:46 100

原创 121. 买卖股票的最佳时机

https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/solution/class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int ...

2019-01-03 13:21:39 106

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除