摘要: # Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def remov 阅读全文
posted @ 2016-10-31 18:41 火金队长 阅读(278) 评论(0) 推荐(0) 编辑
摘要: class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ left_tag=['(','{','['] right_tag=[')','}',']'] stack_list=[] match_dic 阅读全文
posted @ 2016-10-28 16:26 火金队长 阅读(118) 评论(0) 推荐(0) 编辑
摘要: #遍历所有元素,将元素值当做键、元素下标当做值#存放在一个字典中。遍历的时候,#如果发现重复元素,则比较其下标的差值是否小于k,#如果小于则可直接返回True,否则更新字典中该键的值为新的下标class Solution(object): def containsNearbyDuplicate(se 阅读全文
posted @ 2016-10-28 16:25 火金队长 阅读(337) 评论(0) 推荐(0) 编辑
摘要: class Solution(object): def wordPattern(self, pattern, str): """ :type pattern: str :type str: str :rtype: bool """ tag=0 tagdic={} tagList=[] i=0 whi 阅读全文
posted @ 2016-10-26 11:30 火金队长 阅读(185) 评论(0) 推荐(0) 编辑
摘要: #-*- coding: UTF-8 -*-#先判断是否有重叠class Solution(object): def computeArea(self, A, B, C, D, E, F, G, H): """ :type A: int :type B: int :type C: int :type 阅读全文
posted @ 2016-10-26 11:00 火金队长 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 双指针思想:两个指针相隔n-1,每次两个指针向后一步,当后面一个指针没有后继了,前面一个指针的后继就是要删除的节点 # Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self. 阅读全文
posted @ 2016-10-25 21:53 火金队长 阅读(162) 评论(0) 推荐(0) 编辑
摘要: AC代码: class Solution(object): def countAndSay(self, n): """ :type n: int :rtype: str """ n=n-1 if n==0:return str(1) tag=1;stri=str(11) while tag<n: c 阅读全文
posted @ 2016-10-25 21:06 火金队长 阅读(423) 评论(0) 推荐(0) 编辑
摘要: class Solution(object): def isIsomorphic(self, s, t): """ :type s: str :type t: str :rtype: bool """ sdic={} slist=[] tdic={} tlist=[] if len(s)!=len( 阅读全文
posted @ 2016-10-25 19:47 火金队长 阅读(191) 评论(0) 推荐(0) 编辑
摘要: # Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution 阅读全文
posted @ 2016-10-24 21:54 火金队长 阅读(118) 评论(0) 推荐(0) 编辑
摘要: class Solution(object): def getHint(self, secret, guess): """ :type secret: str :type guess: str :rtype: str """ countA,i,numList=0,-1,[[0,0] for i in 阅读全文
posted @ 2016-10-24 17:18 火金队长 阅读(281) 评论(0) 推荐(0) 编辑