### 题意 Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. 给定一个正整数,输出它的补数。补数是对该数的二进制表示取反。 Note: - The given integer is guaranteed to fit within the range of a ...
阅读全文>>2018年5月21日 10:36 作者:nancy 分类:[LeetCode] 1317
### 题意 The Hamming distance between two integers is the number of positions at which the corresponding bits are different. 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目。 Given two integers x and y, calculate the Hamming distance. 给出两个整数 x 和 y,计算它们之间...
阅读全文>>2018年5月21日 09:55 作者:nancy 分类:[LeetCode] 1321
### 题意 Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used. 给定一个整数,编写一个算法将这个数转换为十六进制数。对于负整数,我们通常使用 补码运算 方法。 Note: - 1.All letters in hexadecimal (a-f) must be in lowerc...
阅读全文>>2018年5月20日 23:37 作者:nancy 分类:[LeetCode] 1319
### 题意 A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59). 二进制手表顶部有 4 个 LED 代表小时 (0-11),底部的 6 个 LED 代表分钟 (0-59)。 Each LED represents a zero or one, with the least...
阅读全文>>2018年5月19日 23:59 作者:nancy 分类:[LeetCode] 1313
### 题意 Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. 不使用运算符 + 和 -,计算两整数 a 和 b 的和。 Example: ``` Given a = 1 and b = 2, return 3. ``` ### 思路 不能使用加法和减法,那么就用位操作。下面以计算 5+4 的例子说明如何用位操作实现加法:...
阅读全文>>2018年5月19日 22:44 作者:nancy 分类:[LeetCode] 1365
### 题意 Given an integer (signed 32 bits), write a function to check whether it is a power of 4. 给定一个整数 (32位有符整数型),请写出一个函数来检验它是否是4的幂。 Example: ``` Given num = 16, return true. Given num = 5, return false. ``` Follow up: Could you solve...
阅读全文>>2018年5月18日 15:23 作者:nancy 分类:[LeetCode] 1274
### 题意 Given two strings s and t which consist of only lowercase letters. 给定两个字符串 s 和 t,它们只包含小写字母。 String t is generated by random shuffling string s and then add one more letter at a random position. 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。 ...
阅读全文>>2018年5月15日 15:46 作者:nancy 分类:[LeetCode] 1408
### 题意 Given a non-empty array of integers, every element appears twice except for one. Find that single one. 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。 Note: Your algorithm should have a linear runtime complexity. Could you imp...
阅读全文>>2018年5月13日 18:06 作者:nancy 分类:[LeetCode] 1315
### 题意 Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. 给定一个包含 0, 1, 2, ..., n 中 n 个不同数字的数组,找出数组中缺少的那个数字。 Example 1 ``` Input: [3,0,1] Output: 2 ``` Example 2 ``...
阅读全文>>2018年4月4日 22:31 作者:nancy 分类:[LeetCode] 1348
### 题意 Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. 给定一个大小为 n 的数组,找到其中的众数。众数是指在数组中出现次数大于 ⌊ n/2 ⌋ 的元素。 You may assume that the array is non-empty and the major...
阅读全文>>2018年3月31日 22:04 作者:nancy 分类:[LeetCode] 1332
你还没有登录,请 或者