摘要:
#-*- coding: UTF-8 -*-class Solution(object): def compareVersion(self, version1, version2): """ :type version1: str :type version2: str :rtype: int "" 阅读全文
posted @ 2016-11-13 19:31
火金队长
阅读(237)
评论(0)
推荐(0)
摘要:
class Solution(object): def convertToTitle(self, n): """ :type n: int :rtype: str """ res='' while n>0: tmp=n n=(n-1)/26 res+=chr(65+(tmp-1)%26) retur 阅读全文
posted @ 2016-11-13 19:30
火金队长
阅读(198)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-#2147483648#在32位操作系统中,由于是二进制,#其能最大存储的数据是1111111111111111111111111111111。#正因为此,体现在windows或其他可视系统中的十进制应该为2147483647。#32位数的范围是 -214 阅读全文
posted @ 2016-11-13 19:30
火金队长
阅读(86)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-#由于题目要求不返回任何值,修改原始列表,#因此不能直接将新生成的结果赋值给nums,这样只是将变量指向新的列表,原列表并没有修改。#需要将新生成的结果赋予给nums[:],才能够修改原始列表class Solution(object): def rota 阅读全文
posted @ 2016-11-13 19:30
火金队长
阅读(147)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-# The isBadVersion API is already defined for you.# @param version, an integer# @return a bool# def isBadVersion(version):class 阅读全文
posted @ 2016-11-13 19:29
火金队长
阅读(211)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- class MinStack(object): def __init__(self): """ initialize your data structure here. """ self.Stack=[] self.minStack=[] def pus 阅读全文
posted @ 2016-11-13 19:28
火金队长
阅读(201)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- class Solution(object): def isPalindrome(self, s): """ :type s: str :rtype: bool """ s=s.lower() if s==None:return False isPali 阅读全文
posted @ 2016-11-13 19:28
火金队长
阅读(177)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- #ZigZag Conversion :之字型class Solution(object): def convert(self, s, numRows): """ :type s: str :type numRows: int :rtype: str " 阅读全文
posted @ 2016-11-13 19:27
火金队长
阅读(270)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- #Tags:dynamic programming,sumRange(i,j)=sum(j)-sum(i-1)class NumArray(object): sums=[] def __init__(self, nums): """ initialize 阅读全文
posted @ 2016-11-13 19:26
火金队长
阅读(320)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- #Hint1:#数字i,i的倍数一定不是质数,因此去掉i的倍数,例如5,5*1,5*2,5*3,5*4,5*5都不是质数,应该去掉#5*1,5*2,5*3,5*4 在数字1,2,3,4的时候都已经剔除过,因此数字5,应该从5*5开始#Hint2:#例:# 阅读全文
posted @ 2016-11-13 19:26
火金队长
阅读(252)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- #l1 = ['1','3','2','3','2','1','1']#l2 = sorted(sorted(set(l1),key=l1.index,reverse=False),reverse=True)class Solution(object): 阅读全文
posted @ 2016-11-13 19:25
火金队长
阅读(258)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- #题意:大海捞刀,在长字符串中找出短字符串#AC源码:滑动窗口双指针的方法class Solution(object): def strStr(self, hayStack, needle): """ :type haystack: str :type 阅读全文
posted @ 2016-11-13 19:24
火金队长
阅读(244)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- class Solution: # @param n, an integer # @return an integer def reverseBits(self, n): tmp=str(bin(n))[2:][::-1] for i in xrange 阅读全文
posted @ 2016-11-13 19:23
火金队长
阅读(219)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- #AC源码【意外惊喜,还以为会超时】class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: L 阅读全文
posted @ 2016-11-13 19:23
火金队长
阅读(162)
评论(0)
推荐(0)
摘要:
class Solution(object): def addBinary(self, a, b): """ :type a: str :type b: str :rtype: str """ resA=int(a,base=2) resB=int(b,base=2) sumAB=bin(resA+ 阅读全文
posted @ 2016-11-13 19:22
火金队长
阅读(246)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- #超时# lenA=len(A)# maxSum=[]# count=0# while count<lenA:# tmpSum=0# for i in xrange(lenA):# tmpSum+=i*A[i-count]# maxSum.append( 阅读全文
posted @ 2016-11-13 19:22
火金队长
阅读(259)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- class Solution(object): def findNthDigit(self, n): """ :type n: int :rtype: int """ res=n if n>9: index=1 mul=9 res=0 while Tru 阅读全文
posted @ 2016-11-13 19:21
火金队长
阅读(434)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- #两种方法#方法1:#计算出A和B两个链表的长度分别为m、n;#长度长的链表先走m-n步,之后再一次遍历寻找#方法2:#先走到一个链表的尾部,从尾部开始走;#跳到另一个链表的头部#如果相遇,则相遇点为重合节点class Solution(object): 阅读全文
posted @ 2016-11-13 19:21
火金队长
阅读(618)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- # Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solu 阅读全文
posted @ 2016-11-13 19:20
火金队长
阅读(274)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-class Stack(object): def __init__(self): """ initialize your data structure here. """ self.inQueue=[] self.outQueue=[] def push( 阅读全文
posted @ 2016-11-13 19:19
火金队长
阅读(194)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边【左边和右边】空格)#利用split分离字符串成列表class Solution(object): def lengthOfLastWord(self, s): """ :type s: str :rt 阅读全文
posted @ 2016-11-13 19:19
火金队长
阅读(164)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-class Solution(object): def merge(self, nums1, m, nums2, n): """ :type nums1: List[int] :type m: int :type nums2: List[int] :typ 阅读全文
posted @ 2016-11-13 19:18
火金队长
阅读(335)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-class Solution(object): def isPalindrome(self, head): """ :type head: ListNode :rtype: bool """ if head==None or head.next==None 阅读全文
posted @ 2016-11-13 19:18
火金队长
阅读(201)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-#利用栈的思想#如果输入的左测扩则入栈,如果输入为右侧扩,判断其是否与当前栈顶配对,如果匹配则删除这一对,否则return False#'(', ')', '{', '}', '[' and ']'class Solution(object): def i 阅读全文
posted @ 2016-11-13 19:17
火金队长
阅读(272)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-#遍历所有元素,将元素值当做键、元素下标当做值#存放在一个字典中。遍历的时候,#如果发现重复元素,则比较其下标的差值是否小于k,#如果小于则可直接返回True,否则更新字典中该键的值为新的下标class Solution(object): def cont 阅读全文
posted @ 2016-11-13 19:17
火金队长
阅读(210)
评论(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-11-13 19:16
火金队长
阅读(161)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-class Solution(object): def wordPattern(self, pattern, str): """ :type pattern: str :type str: str :rtype: bool """ tag=0 tagdic 阅读全文
posted @ 2016-11-13 19:15
火金队长
阅读(150)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-#双指针思想,两个指针相隔n-1,每次两个指针向后一步,当后面一个指针没有后继了,前面一个指针的后继就是要删除的节点# Definition for singly-linked list.# class ListNode(object):# def __i 阅读全文
posted @ 2016-11-13 19:14
火金队长
阅读(134)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- # Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.rig 阅读全文
posted @ 2016-11-13 19:13
火金队长
阅读(126)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- 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(1 阅读全文
posted @ 2016-11-13 19:13
火金队长
阅读(226)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*- #转换法class Solution(object): def isIsomorphic(self, s, t): """ :type s: str :type t: str :rtype: bool """ sdic={} slist=[] tdic= 阅读全文
posted @ 2016-11-13 19:12
火金队长
阅读(176)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.righ 阅读全文
posted @ 2016-11-13 19:11
火金队长
阅读(152)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-class Solution(object): def getHint(self, secret, guess): """ :type secret: str :type guess: str :rtype: str """ countA,i,numLis 阅读全文
posted @ 2016-11-13 19:08
火金队长
阅读(267)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-#特定的九个格内1-9的个数至多为1#依次检查每行,每列,每个子九宫格是否出现重复元素,如果出现返回false,否则返回true.class Solution(object): def isValidSudoku(self, board): """ :ty 阅读全文
posted @ 2016-11-13 19:07
火金队长
阅读(163)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-# The guess API is already defined for you.# @param num, your guess# @return -1 if my number is lower, 1 if my number is higher, 阅读全文
posted @ 2016-11-13 19:07
火金队长
阅读(161)
评论(0)
推荐(0)
摘要:
#-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1、以0开头的字符串,如01201215#2、以正负号开头的字符串,如‘+121215’;‘-1215489’#3、1和2和空格混合形式【顺序只能是正负号-0,空格位置可以随意】的:‘+00121515’#4、 阅读全文
posted @ 2016-11-13 19:04
火金队长
阅读(810)
评论(0)
推荐(0)