leecode
shitfly
啥也不会
展开
-
leetcode day1
LeetCode 557. Reverse Words in a String IIIGiven a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:原创 2017-04-21 16:38:32 · 253 阅读 · 0 评论 -
leetcode13
Spiral Matrix#coding=utf-8class Solution(object): def spiralOrder(self, matrix): """ :type matrix: List[List[int]] :rtype: List[int] """ res=[]原创 2017-08-20 18:56:08 · 312 阅读 · 0 评论 -
leetcode10
Combination Sum II#coding=utf-8class Solution(object): def combinationSum2(self, candidates, target): """ :type candidates: List[int] :type target: int :rtype原创 2017-07-28 10:29:55 · 267 阅读 · 0 评论 -
leetcode11
Wildcard Matching 看的大神的答案。当p[pPointer] == ‘?’ or p[pPointer] == s[sPointer]的时候,两个指针都向后移一位,当p[pPointer] == ‘*’的时候,用star记录下p当前的位置,pPointer向后移,ss记录s当前的位置,如果上面的条件都不满足了,看star是不是-1,不是的话,把pPointer拉回到star的下一原创 2017-08-02 10:25:27 · 472 阅读 · 1 评论 -
leetcode9
Count and Say这个题目的意思是n=1时输出字符串1;n=2时,数上次字符串中的数值个数,因为上次字符串有1个1,所以输出11;n=3时,由于上次字符是11,有2个1,所以输出21;n=4时,由于上次字符串是21,有1个2和1个1,所以输出1211。#coding=utf-8class Solution(object): def countAndSay(self,原创 2017-07-23 18:58:22 · 151 阅读 · 0 评论 -
leetcode6
Implement strStr()#coding=utf-8class Solution(object): def strStr(self, haystack, needle): """ :type haystack: str :type needle: str :rtype: int """原创 2017-07-19 08:20:40 · 177 阅读 · 0 评论 -
leetcode5
Swap Nodes in Pairs还是设置一个头结点比较好操作,直接操作不太顺利。。。class Solution(object): def swapPairs(self, head): """ :type head: ListNode :rtype: ListNode """ if head is None原创 2017-07-18 08:56:19 · 186 阅读 · 0 评论 -
leetcode8
Search Insert Position#coding=utf-8class Solution(object): def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int原创 2017-07-21 16:02:11 · 416 阅读 · 0 评论 -
leetcode4
4Sum和3Sum差不多#coding=utf-8class Solution(object): def fourSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[List[int]] """原创 2017-07-11 12:27:26 · 284 阅读 · 0 评论 -
leetcode7
Longest Valid Parentheses昨天刚听了这道题的讲解,今天就做到了。。。有几个坑count存放的当前位置最长的有效子串,这个碰到的主要是当有效的子串到达了s[0],要判断一下。#coding=utf-8class Solution(object): def longestValidParentheses(self, s): """ :ty原创 2017-07-20 08:58:47 · 256 阅读 · 0 评论 -
leetcode3
String to Integer (atoi)import reclass Solution(object): def myAtoi(self, str): INT_MAX=2147483647 INT_MIN=-2147483648 temp=0 if str=='': return 0原创 2017-05-12 14:56:47 · 226 阅读 · 0 评论 -
leetcode2
题目要求可以直接去leetcode搜 Longest Palindromic Substringclass Solution(object): def longestPalindrome(self,s): d={} d[-1]=s[0] if len(s)==1: return s for i in r原创 2017-04-28 09:12:04 · 297 阅读 · 0 评论 -
leetcode12
Permutations II 剪枝#coding=utf-8class Solution(object): def permuteUnique(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ if len(num原创 2017-08-06 13:23:01 · 316 阅读 · 0 评论