【leetcode 136】136. Single Number】的更多相关文章

#-*- 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, otherwise return 0# def guess(num):#binary searchclass Solution(object):    def guessNumber(self, n…
#回文数#Method1:将整数转置和原数比较,一样就是回文数:负数不是回文数#这里反转整数时不需要考虑溢出,但不代表如果是C/C++等语言也不需要考虑class Solution(object):    def isPalindrome(self, x):        """        :type x: int        :rtype: bool        """        if x<0:return False    …
#-*- 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',            14:'e',            15:'f'}            def t…
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:                tuple=divmod(num,value)            …
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find >the two elements that a…
[LeetCode]137. Single Number II 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/single-number-ii/description/ 题目描述: Given an array of integers, every element appears three times except for one, which appears exactly once. Find that singl…
目录 [LeetCode题解]7_反转整数 描述 方法一 思路 Java 实现 类似的 Java 实现 Python 实现 方法二:转化为求字符串的倒序 Java 实现 Python 实现 [LeetCode题解]7_反转整数 描述 给定一个 32 位有符号整数,将整数中的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出: 21 注意: 假设我们的环境只能存储 32 位有符号整数,其数值范围是 \([-2…
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space. 思路: [LeetCode 169]Majority Element 的拓展,这回要求的是出现次数超过三分之一次的数字咯,动动我们的大脑思考下,这样的数最多会存在几个呢,当然是2个嘛.因此,接着上一题的方…
Permutation Sequence The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3): "123" "132" "213" "231" &q…
我准备开始一个新系列[LeetCode题解],用来记录刷LeetCode题,顺便复习一下数据结构与算法. 1. 二叉树 二叉树(binary tree)是一种极为普遍的数据结构,树的每一个节点最多只有两个节点--左孩子结点与右孩子结点.C实现的二叉树: struct TreeNode { int val; struct TreeNode *left; // left child struct TreeNode *right; // right child }; DFS DFS的思想非常朴素:根据…