摘要: #-*- 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-10-24 15:27 火金队长 阅读(153) 评论(0) 推荐(0) 编辑
摘要: # 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, otherwise return 0# d 阅读全文
posted @ 2016-10-24 14:36 火金队长 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 深度优先搜索 # Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution: 阅读全文
posted @ 2016-10-24 11:32 火金队长 阅读(589) 评论(0) 推荐(0) 编辑
摘要: 数独规则如下:相当于一个9*9的矩阵 代码如下:#特定的九个格内1-9的个数至多为1#依次检查每行,每列,每个子九宫格是否出现重复元素,如果出现返回false,否则返回true.class Solution(object): def isValidSudoku(self, board): """ : 阅读全文
posted @ 2016-10-14 21:54 火金队长 阅读(342) 评论(0) 推荐(0) 编辑
摘要: #回文数#Method1:将整数转置和原数比较,一样就是回文数;负数不是回文数#这里反转整数时不需要考虑溢出,但不代表如果是C/C++等语言也不需要考虑class Solution(object): def isPalindrome(self, x): """ :type x: int :rtype 阅读全文
posted @ 2016-10-13 10:40 火金队长 阅读(329) 评论(0) 推荐(0) 编辑
摘要: #-*- 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 火金队长 阅读(209) 评论(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 火金队长 阅读(165) 评论(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 火金队长 阅读(233) 评论(0) 推荐(0) 编辑
摘要: #-*- coding: UTF-8 -*- #filter()函数可以对序列做过滤处理,就是说可以使用一个自定的函数过滤一个序列,#把序列的每一项传到自定义的过滤函数里处理,并返回结果做过滤。最终一次性返回过滤后的结果。class Solution(object):# def filterDemo 阅读全文
posted @ 2016-10-12 17:17 火金队长 阅读(231) 评论(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 火金队长 阅读(153) 评论(0) 推荐(0) 编辑