338. Counting Bits"

338. Counting Bits Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1’s in the binary representation of i. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Example 1: Input: n = 2 Output: [0,1,1] Explanation: 0 --> 0 1 --> 1 2 --> 10 Example 2: Input: n = 5 Output: [0,1,1,2,1,2] Explanation: 0 --> 0 1 --> 1 2 --> 10 3 --> 11 4 --> 100 5 --> 101 Constraints:...

<span title='2021-06-13 00:00:00 +0000 UTC'>June 13, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

136. Single Number

136. Single Number Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. You must implement a solution with a linear runtime complexity and use only constant extra space. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Example 1: Input: nums = [2,2,1] Output: 1 Example 2: Input: nums = [4,1,2,1,2] Output: 4 Example 3: Input: nums = [1] Output: 1 Constraints:...

<span title='2021-06-11 00:00:00 +0000 UTC'>June 11, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

137. Single Number II

137. Single Number II Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it. You must implement a solution with a linear runtime complexity and use only constant extra space. 1 2 3 4 5 6 7 8 9 Example 1: Input: nums = [2,2,3,2] Output: 3 Example 2: Input: nums = [0,1,0,1,0,1,99] Output: 99 Constraints:...

<span title='2021-06-11 00:00:00 +0000 UTC'>June 11, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

190. Reverse Bits

190. Reverse Bits Reverse 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 implementation, as the integer’s internal binary representation is the same, whether it is signed or unsigned. In Java, the compiler represents the signed integers using 2’s complement notation....

<span title='2021-06-11 00:00:00 +0000 UTC'>June 11, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

260. Single Number III

260. Single Number III Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order. You must write an algorithm that runs in linear runtime complexity and uses only constant extra space. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Example 1: Input: nums = [1,2,1,3,2,5] Output: [3,5] Explanation: [5, 3] is also a valid answer....

<span title='2021-06-11 00:00:00 +0000 UTC'>June 11, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

268. Missing Number

268. Missing Number Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Follow up: Could you implement a solution using only O(1) extra space complexity and O(n) runtime complexity? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Example 1: Input: nums = [3,0,1] Output: 2 Explanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3]....

<span title='2021-06-11 00:00:00 +0000 UTC'>June 11, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

389. Find the Difference

389. Find the Difference You 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. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Example 1: Input: s = "abcd", t = "abcde" Output: "e" Explanation: 'e' is the letter that was added....

<span title='2021-06-11 00:00:00 +0000 UTC'>June 11, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx