摘要: #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作。下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100;#2. 用and(&)操作得到所有位上的进位carry=0100;#3. 用xor(^)操作找到a 阅读全文
posted @ 2016-10-12 17:19 火金队长 阅读(222) 评论(0) 推荐(0)
摘要: #-*- coding: UTF-8 -*- class Solution(object): def canConstruct(self, ransomNote, magazine): ransomNote=list(ransomNote) magezine=list(magazine) for r 阅读全文
posted @ 2016-10-12 17:18 火金队长 阅读(168) 评论(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-10-12 17:18 火金队长 阅读(237) 评论(0) 推荐(0)
摘要: #-*- coding: UTF-8 -*- #filter()函数可以对序列做过滤处理,就是说可以使用一个自定的函数过滤一个序列,#把序列的每一项传到自定义的过滤函数里处理,并返回结果做过滤。最终一次性返回过滤后的结果。class Solution(object):# def filterDemo 阅读全文
posted @ 2016-10-12 17:17 火金队长 阅读(237) 评论(0) 推荐(0)
摘要: #-*- coding: UTF-8 -*- #求两个集合的交集class Solution(object): def intersection(self, nums1, nums2): resultList=list(set(nums1).intersection(set(nums2))) ret 阅读全文
posted @ 2016-10-12 17:16 火金队长 阅读(159) 评论(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-10-12 17:16 火金队长 阅读(115) 评论(0) 推荐(0)
摘要: #-*- coding: UTF-8 -*- class Solution(object): def findTheDifference(self, s, t): s=sorted(list(s)) t=sorted(list(t)) for st in s: p=t.index(st) del t 阅读全文
posted @ 2016-10-12 17:15 火金队长 阅读(219) 评论(0) 推荐(0)
摘要: #-*- coding: UTF-8 -*- class Solution(object): hexDic={0:'0',1:'1',2:'2',3:'3',4:'4',5:'5',6:'6',7:'7',8:'8',9:'9',\ 10:'a', 11:'b', 12:'c', 13:'d', 1 阅读全文
posted @ 2016-10-12 17:14 火金队长 阅读(343) 评论(0) 推荐(0)
摘要: #-*- coding: UTF-8 -*- from itertools import combinationsclass Solution(object): hourList=[8,4,2,1] minList=[32,16,8,4,2,1] def selectHour(self,hourNu 阅读全文
posted @ 2016-10-12 17:14 火金队长 阅读(466) 评论(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-10-12 17:13 火金队长 阅读(181) 评论(0) 推荐(0)
摘要: #Method1:动态规划##当有n个台阶时,可供选择的走法可以分两类:###1,先跨一阶再跨完剩下n-1阶;###2,先跨2阶再跨完剩下n-2阶。###所以n阶的不同走法的数目是n-1阶和n-2阶的走法数的和class Solution(object): def climbStairs(self, 阅读全文
posted @ 2016-10-12 17:12 火金队长 阅读(96) 评论(0) 推荐(0)
摘要: class Solution: # @param digits, a list of integer digits # @return a list of integer digits def plusOne(self, digits): carry=1 for i in range(len(dig 阅读全文
posted @ 2016-10-12 17:12 火金队长 阅读(158) 评论(0) 推荐(0)
摘要: #-*- coding: UTF-8 -*- from collections import Counterclass Solution(object): def longestPalindrome(self, s): """ :type s: str :rtype: int """ lopa=0 阅读全文
posted @ 2016-10-12 17:11 火金队长 阅读(260) 评论(0) 推荐(0)
摘要: #-*- coding: UTF-8 -*- class Solution(object): def firstUniqChar(self, s): s=s.lower() sList=list(s) numCdic={} for c in s: numCdic[c]=numCdic[c]+1 if 阅读全文
posted @ 2016-10-12 17:10 火金队长 阅读(231) 评论(0) 推荐(0)
摘要: #-*- coding: UTF-8 -*- class Solution(object): def intersect(self, nums1, nums2): if len(nums1)<len(nums2): tmp=nums1 nums1=nums2 nums2=tmp tmpdic={} 阅读全文
posted @ 2016-10-12 17:09 火金队长 阅读(121) 评论(0) 推荐(0)
摘要: #-*- coding: UTF-8 -*- class Solution(object): def isPowerOfFour(self, num): """ :type num: int :rtype: bool """ if num<=0:return False while True: if 阅读全文
posted @ 2016-10-12 17:08 火金队长 阅读(173) 评论(0) 推荐(0)
摘要: #-*- coding: UTF-8 -*- class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ for i in r 阅读全文
posted @ 2016-10-12 17:07 火金队长 阅读(149) 评论(0) 推荐(0)
摘要: #-*- coding: UTF-8 -*- class Solution(object): def isPowerOfThree(self, n): if n<=0: return False while True: if n==3 or n==1: return True tuple=divmo 阅读全文
posted @ 2016-10-12 17:07 火金队长 阅读(155) 评论(0) 推荐(0)
摘要: class Solution(object): def isUgly(self, num): if num<=0:return False comlist=[2,3,5];modflag=0 while True: if num==1:break for value in comlist: tupl 阅读全文
posted @ 2016-10-12 17:05 火金队长 阅读(162) 评论(0) 推荐(0)
摘要: #-*- coding: UTF-8 -*-class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if len(nums)<=1:return len(n 阅读全文
posted @ 2016-10-12 17:05 火金队长 阅读(222) 评论(0) 推荐(0)