摘要: 030 Substring with Concatenation of All Words用一个dictiionary来记录当前对应还有多少需要match的word。 dict.copy()用来copy dictionary.from collections import defaultdictcl... 阅读全文
posted @ 2015-07-17 14:32 dapanshe 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 064 Minimum Path Sum纯dpclass Solution: # @param {integer[][]} grid # @return {integer} def minPathSum(self, grid): m = len(grid) ... 阅读全文
posted @ 2015-07-17 12:28 dapanshe 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 034 Search for a Range二分搜索, 搜左右部分稍微有些不同 需要注意class Solution: # @param {integer[]} nums # @param {integer} target # @return {integer[]} def ... 阅读全文
posted @ 2015-07-17 12:11 dapanshe 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 232 Implement Queue using Stacks用2个stack 完成 代码如下class Queue: # initialize your data structure here. def __init__(self): self.stackA = [] ... 阅读全文
posted @ 2015-07-17 08:46 dapanshe 阅读(84) 评论(0) 推荐(0) 编辑
摘要: 234 Palindrome Linked List这道题如果不要求space O(1) 代码写起来就相当简单。 但是要求 O(1),唯一的方法就是reverse 前半部分linked List 在做比较, 稍微注意长度为奇偶时一点小小的区别。写起来还是很费劲的class Solution: ... 阅读全文
posted @ 2015-07-17 08:29 dapanshe 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 238 Product of Array Except Self从头部 和 尾部各扫描一遍class Solution: # @param {integer[]} nums # @return {integer[]} def productExceptSelf(self, nums... 阅读全文
posted @ 2015-07-17 07:29 dapanshe 阅读(108) 评论(0) 推荐(0) 编辑