leetcode位运算
Bryan要加油
这个作者很懒,什么都没留下…
展开
-
526. Beautiful Arrangement[Medium](Leetcode每日一题-2021.08.16)
位运算DP原创 2021-08-17 20:11:54 · 291 阅读 · 0 评论 -
剑指 Offer 15. 二进制中1的个数[Easy](Leetcode每日一题-2021.06.23)
Problem请实现一个函数,输入一个整数(以二进制串形式),输出该数二进制表示中 1 的个数。例如,把 9 表示成二进制是 1001,有 2 位是 1。因此,如果输入 9,则该函数输出 2。提示:输入必须是长度为 32 的 二进制串 。Example1输入:00000000000000000000000000001011输出:3解释:输入的二进制串 00000000000000000000000000001011 中,共有三位为 ‘1’。Example2输入:000000000原创 2021-06-23 21:50:49 · 299 阅读 · 0 评论 -
401. Binary Watch[Easy](Leetcode每日一题-2021.06.21)--抄答案
Problem原创 2021-06-21 22:26:08 · 408 阅读 · 0 评论 -
342. Power of Four[Easy]-210531
ProblemGiven an integer n, return true if it is a power of four. Otherwise, return false.An integer n is a power of four, if there exists an integer x such that n == 4^x.Constraints:-2^31 <= n <= 2^31 - 1Example1Input: n = 16Output: trueE原创 2021-05-31 08:35:58 · 470 阅读 · 0 评论 -
231. Power of Two[Easy]-210530
ProblemGiven an integer n, return true if it is a power of two. Otherwise, return false.An integer n is a power of two, if there exists an integer x such that n == 2^x.Constraints:-2^31 <= n <= 2^31 - 1Example1Input: n = 1Output: trueExpla原创 2021-05-30 11:40:36 · 261 阅读 · 0 评论 -
477.Total Hamming Distance[Medium](Leetcode每日一题-2021.05.28)抄
ProblemThe Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given an integer array nums, return the sum of Hamming distances between all the pairs of the integers in nums.Constraints:1 <原创 2021-05-28 22:07:18 · 687 阅读 · 0 评论 -
461. Hamming Distance[Easy](Leetcode每日一题-2021.05.27)
ProblemThe Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, return the Hamming distance between them.Constraints:0 <= x, y <= 2^31 - 1Example1Input: x原创 2021-05-27 08:37:31 · 342 阅读 · 0 评论 -
1787. Make the XOR of All Segments Equal to Zero[Hard](Leetcode每日一题-2021.05.25)--抄答案
ProblemYou are given an array nums and an integer k. The XOR of a segment [left, right] where left <= right is the XOR of all the elements with indices between left and right, inclusive: nums[left] XOR nums[left+1] XOR … XOR nums[right].Return原创 2021-05-25 08:41:31 · 691 阅读 · 0 评论 -
1707. Maximum XOR With an Element From Array[Hard](Leetcode每日一题-2021.05.23)--抄答案
ProblemYou are given an array nums consisting of non-negative integers. You are also given a queries array, where queries[i] = [xi, mi].The answer to the ith query is the maximum bitwise XOR value of xi and any element of nums that does not exceed mi. In原创 2021-05-23 09:32:34 · 179 阅读 · 0 评论 -
1738. Find Kth Largest XOR Coordinate Value[Medium](Leetcode每日一题-2021.05.19)
ProblemYou are given a 2D matrix of size m x n, consisting of non-negative integers. You are also given an integer k.The value of coordinate (a, b) of the matrix is the XOR of all matrix[i][j] where 0 <= i <= a < m and 0 <= j <= b < n (原创 2021-05-19 08:33:08 · 545 阅读 · 0 评论 -
1442. Count Triplets That Can Form Two Arrays of Equal XOR[Medium](Leetcode每日一题-2021.05.18)
ProblemGiven an array of integers arr.We want to select three indices i, j and k where (0 <= i < j <= k < arr.length).Let’s define a and b as follows:a = arr[i] ^ arr[i + 1] ^ … ^ arr[j - 1]b = arr[j] ^ arr[j + 1] ^ … ^ arr[k]Note that ^原创 2021-05-18 22:17:29 · 357 阅读 · 0 评论 -
421. Maximum XOR of Two Numbers in an Array[Medium](Leetcode每日一题-2021.05.15)--抄答案
ProblemGiven an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 ≤ i ≤ j < n.Constraints:1 <= nums.length <= 2 * 1040 <= nums[i] <= 231 - 1Example1Input: nums = [3,10,5,25,2,8]Output: 28Explanation: Th原创 2021-05-16 20:06:48 · 605 阅读 · 0 评论 -
1310. XOR Queries of a Subarray[Medium](Leetcode每日一题-2021.05.12)
ProblemGiven the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor … xor arr[Ri] ). Return an array containing the result for th原创 2021-05-12 08:54:27 · 523 阅读 · 0 评论 -
1734. Decode XORed Permutation[Medium](Leetcode每日一题-2021.05.11)
ProblemThere is an integer array perm that is a permutation of the first n positive integers, where n is always odd.It was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[i + 1]. For example, if perm =原创 2021-05-12 08:53:42 · 399 阅读 · 0 评论 -
1486. XOR Operation in an Array(Leetcode每日一题-2021.05.07)
ProblemGiven an integer n and an integer start.Define an array nums where nums[i] = start + 2*i (0-indexed) and n == nums.length.Return the bitwise XOR of all elements of nums.Constraints:1 <= n <= 10000 <= start <= 1000n == nums.length原创 2021-05-07 21:13:26 · 223 阅读 · 0 评论 -
1720. Decode XORed Array(Leetcode每日一题-2021.05.06)
ProblemThere is a hidden integer array arr that consists of n non-negative integers.It was encoded into another integer array encoded of length n - 1, such that encoded[i] = arr[i] XOR arr[i + 1]. For example, if arr = [1,0,2,1], then encoded = [1,2,3].原创 2021-05-06 08:36:27 · 504 阅读 · 0 评论 -
137. Single Number II(Leetcode每日一题-2021.04.30)--抄答案
ProblemGiven an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it.Constraints:1 <= nums.length <= 3 * 10^4-2^31 <= nums[i] <= 2^31 - 1Each element原创 2021-04-30 21:43:38 · 95 阅读 · 1 评论 -
190. Reverse Bits(Leetcode每日一题-2021.03.29)
ProblemReverse bits of a given 32 bits unsigned integer.Note:Note that in some languages such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementa原创 2021-03-29 21:45:31 · 223 阅读 · 0 评论 -
191. Number of 1 Bits(Leetcode每日一题-2021.03.22)
ProblemWrite a function that takes an unsigned integer and returns the number of ‘1’ bits it has (also known as the Hamming weight).Note:Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given原创 2021-03-22 20:08:03 · 178 阅读 · 0 评论 -
338. Counting Bits(Leetcode每日一题-2021.03.03)--抄答案
ProblemGiven 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 and return them as an array.Example1Input: 2Output: [0,1,1]Example2Input: 5Output: [0,1,1,2,1,原创 2021-03-03 18:18:35 · 118 阅读 · 1 评论 -
1178. Number of Valid Words for Each Puzzle(Leetcode每日一题-2021.02.26)--抄答案
ProblemWith respect to a given puzzle string, a word is valid if both the following conditions are satisfied:word contains the first letter of puzzle.For each letter in word, that letter is in puzzle.For example, if the puzzle is “abcdefg”, then valid原创 2021-02-26 20:31:33 · 270 阅读 · 0 评论 -
389. Find the Difference(Leetcode每日一题-2020.12.18)
ProblemYou are given two strings s and t.String t is generated by random shuffling string s and then add one more letter at a random position.Return the letter that was added to t.Constraints:0 <= s.length <= 1000t.length == s.length + 1s and原创 2020-12-18 20:07:44 · 222 阅读 · 1 评论 -
1356. Sort Integers by The Number of 1 Bits(Leetcode每日一题-2020.11.06)
ProblemGiven an integer array arr. You have to sort the integers in the array in ascending order by the number of 1’s in their binary representation and in case of two or more integers have the same number of 1’s you have to sort them in ascending order.原创 2020-11-06 22:12:43 · 265 阅读 · 0 评论 -
201. Bitwise AND of Numbers Range(Leetcode每日一题-2020.08.23)
ProblemGiven a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.Example1Input: [5,7]Output: 4Example2Input: [0,1]Output: 0Solutionclass Solution {public: int rangeBitwi原创 2020-08-23 20:47:57 · 176 阅读 · 0 评论 -
136. Single Number(Leetcode每日一题-2020.05.14)
ProblemGiven 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 implement it without using extra memory?Example1Input: [2,2,1]Output:原创 2020-05-14 22:01:32 · 154 阅读 · 0 评论 -
1290. Convert Binary Number in a Linked List to Integer
ProblemGiven head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number.Return th...原创 2020-05-05 19:59:32 · 195 阅读 · 0 评论 -
面试题56 - I. 数组中数字出现的次数(Leetcode每日一题-2020.04.28)
Problem一个整型数组 nums 里除两个数字之外,其他数字都出现了两次。请写程序找出这两个只出现一次的数字。要求时间复杂度是O(n),空间复杂度是O(1)。Example1输入:nums = [4,1,4,6]输出:[1,6] 或 [6,1]Example2输入:nums = [1,2,10,4,1,4,3,3]输出:[2,10] 或 [10,2]Solutiona...原创 2020-04-28 22:31:57 · 233 阅读 · 0 评论 -
289. Game of Life(Leetcode每日一题-2020.04.02)
ProblemAccording to the Wikipedia’s article: “The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.”Given a board with...原创 2020-04-02 20:56:32 · 266 阅读 · 0 评论