摘要: #-*- 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 火金队长 阅读(230) 评论(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 火金队长 阅读(190) 评论(0) 推荐(0) 编辑
摘要: #-*- coding: UTF-8 -*-#2147483648#在32位操作系统中,由于是二进制,#其能最大存储的数据是1111111111111111111111111111111。#正因为此,体现在windows或其他可视系统中的十进制应该为2147483647。#32位数的范围是 -214 阅读全文
posted @ 2016-11-13 19:30 火金队长 阅读(80) 评论(0) 推荐(0) 编辑
摘要: #-*- coding: UTF-8 -*-#由于题目要求不返回任何值,修改原始列表,#因此不能直接将新生成的结果赋值给nums,这样只是将变量指向新的列表,原列表并没有修改。#需要将新生成的结果赋予给nums[:],才能够修改原始列表class Solution(object): def rota 阅读全文
posted @ 2016-11-13 19:30 火金队长 阅读(139) 评论(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 火金队长 阅读(205) 评论(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 火金队长 阅读(190) 评论(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 火金队长 阅读(170) 评论(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 火金队长 阅读(265) 评论(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 火金队长 阅读(311) 评论(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 火金队长 阅读(237) 评论(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 火金队长 阅读(249) 评论(0) 推荐(0) 编辑
摘要: #-*- coding: UTF-8 -*- #题意:大海捞刀,在长字符串中找出短字符串#AC源码:滑动窗口双指针的方法class Solution(object): def strStr(self, hayStack, needle): """ :type haystack: str :type 阅读全文
posted @ 2016-11-13 19:24 火金队长 阅读(236) 评论(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 火金队长 阅读(214) 评论(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 火金队长 阅读(157) 评论(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 火金队长 阅读(239) 评论(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 火金队长 阅读(245) 评论(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 火金队长 阅读(421) 评论(0) 推荐(0) 编辑
摘要: #-*- coding: UTF-8 -*- #两种方法#方法1:#计算出A和B两个链表的长度分别为m、n;#长度长的链表先走m-n步,之后再一次遍历寻找#方法2:#先走到一个链表的尾部,从尾部开始走;#跳到另一个链表的头部#如果相遇,则相遇点为重合节点class Solution(object): 阅读全文
posted @ 2016-11-13 19:21 火金队长 阅读(608) 评论(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 火金队长 阅读(267) 评论(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 火金队长 阅读(191) 评论(0) 推荐(0) 编辑