位运算
文章平均质量分 58
小榕流光
这个作者很懒,什么都没留下…
展开
-
[leetcode] 136. Single Number 解题报告
题目链接:https://leetcode.com/problems/single-number/Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runti原创 2015-12-30 02:51:24 · 515 阅读 · 0 评论 -
数组中两个元素异或求最大值
给一个整数数组,求数组中两个元素异或的最大值.思路:naive的做法是两两异或求最大值,时间复杂度为O(n*n),但是还有一种O(n)的解法,利用字典树Trie来实现.其思路是利用数组中的每个元素二进制表示形式建一棵树,我看到网上大多数解法都开了太大的数组空间,不知道为什么,但是我觉得没有必要.只要用现有的数组元素二进制值建一棵深度为33的树即可,从根到叶子结点的路径就代表了一个元原创 2016-09-28 22:56:57 · 7236 阅读 · 1 评论 -
[leetcode] 389. Find the Difference 解题报告
题目链接: https://leetcode.com/problems/find-the-difference/Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one原创 2016-08-29 14:10:50 · 3053 阅读 · 0 评论 -
[leetcode] 393. UTF-8 Validation 解题报告
题目链接:https://leetcode.com/problems/utf-8-validation/A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:For 1-byte character, the first bit is a 0, followed b原创 2016-09-09 08:54:54 · 2527 阅读 · 0 评论 -
[leetcode] 260. Single Number III 解题报告
题目链接:https://leetcode.com/problems/single-number-iii/Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the tw原创 2016-01-03 05:53:56 · 566 阅读 · 0 评论 -
[leetcode] 190. Reverse Bits 解题报告
题目链接:https://leetcode.com/problems/reverse-bits/Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100)原创 2016-02-25 00:06:21 · 661 阅读 · 0 评论 -
[leetcode] 318. Maximum Product of Word Lengths 解题报告
题目链接: https://leetcode.com/problems/maximum-product-of-word-lengths/Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share com原创 2016-03-29 15:21:50 · 552 阅读 · 0 评论 -
[leetcode] 191. Number of 1 Bits 解题报告
题目链接: https://leetcode.com/problems/number-of-1-bits/Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For exampl原创 2016-05-19 07:17:41 · 452 阅读 · 0 评论 -
[leetcode] 36. Valid Sudoku 解题报告
题目链接:https://leetcode.com/problems/valid-sudoku/Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are fil原创 2015-12-29 15:05:42 · 908 阅读 · 0 评论 -
[leetcode] 137. Single Number II 解题报告
题目链接:https://leetcode.com/problems/single-number-ii/Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a lin原创 2016-01-03 07:03:51 · 869 阅读 · 0 评论 -
[leetcode] 268. Missing Number 解题报告
题目链接:https://leetcode.com/problems/missing-number/Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given n原创 2016-01-03 10:36:10 · 409 阅读 · 0 评论 -
[leetcode] 338. Counting Bits 解题报告
题目链接: https://leetcode.com/problems/counting-bits/Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation原创 2016-04-13 08:54:39 · 1269 阅读 · 1 评论 -
[leetcode] 201. Bitwise AND of Numbers Range解题报告
题目链接: https://leetcode.com/problems/bitwise-and-of-numbers-range/Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.思路: 有两种思路来做这题, 第一种是从后往前每次 n = (原创 2016-03-27 13:58:44 · 689 阅读 · 0 评论 -
[leetcode] 421. Maximum XOR of Two Numbers in an Array 解题报告
题目链接: https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.Find the maximum result of ai XOR原创 2016-12-01 10:49:34 · 1216 阅读 · 0 评论