Skip to content

Commit e4e2b56

Browse files
authored
Improved task 190.
1 parent 656ff42 commit e4e2b56

File tree

4 files changed

+21
-30
lines changed

4 files changed

+21
-30
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.5'
10591059
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10601060
|-|-|-|-|-|-
10611061
| 0191 |[Number of 1 Bits](src/main/kotlin/g0101_0200/s0191_number_of_1_bits/Solution.kt)| Easy | Top_Interview_Questions, Bit_Manipulation | 237 | 68.44
1062-
| 0190 |[Rotate Array](src/main/kotlin/g0101_0200/s0190_reverse_bits/Solution.kt)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer | 198 | 81.82
1062+
| 0190 |[Reverse Bits](src/main/kotlin/g0101_0200/s0190_reverse_bits/Solution.kt)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer | 198 | 81.82
10631063
| 0338 |[Counting Bits](src/main/kotlin/g0301_0400/s0338_counting_bits/Solution.kt)| Easy | Top_100_Liked_Questions, Dynamic_Programming, Bit_Manipulation | 186 | 99.26
10641064
| 0029 |[Divide Two Integers](src/main/kotlin/g0001_0100/s0029_divide_two_integers/Solution.kt)| Medium | Top_Interview_Questions, Math, Bit_Manipulation | 281 | 31.67
10651065

@@ -1390,7 +1390,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.5'
13901390

13911391
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
13921392
|-|-|-|-|-|-
1393-
| 0190 |[Rotate Array](src/main/kotlin/g0101_0200/s0190_reverse_bits/Solution.kt)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer | 198 | 81.82
1393+
| 0190 |[Reverse Bits](src/main/kotlin/g0101_0200/s0190_reverse_bits/Solution.kt)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer | 198 | 81.82
13941394
| 0136 |[Single Number](src/main/kotlin/g0101_0200/s0136_single_number/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation | 344 | 83.63
13951395

13961396
### Algorithm II
@@ -1573,7 +1573,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.5'
15731573
| 0198 |[House Robber](src/main/kotlin/g0101_0200/s0198_house_robber/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Algorithm_I_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_3, Level_2_Day_12_Dynamic_Programming, Udemy_Dynamic_Programming | 156 | 92.24
15741574
| 0192 |[Word Frequency](src/main/kotlin/g0101_0200/s0192_word_frequency/script.sh)| Medium | Shell | 114 | 73.60
15751575
| 0191 |[Number of 1 Bits](src/main/kotlin/g0101_0200/s0191_number_of_1_bits/Solution.kt)| Easy | Top_Interview_Questions, Bit_Manipulation, Algorithm_I_Day_13_Bit_Manipulation, Programming_Skills_I_Day_2_Operator, Udemy_Bit_Manipulation | 237 | 68.44
1576-
| 0190 |[Rotate Array](src/main/kotlin/g0101_0200/s0190_reverse_bits/Solution.kt)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer, Algorithm_I_Day_14_Bit_Manipulation, Udemy_Bit_Manipulation | 198 | 81.82
1576+
| 0190 |[Reverse Bits](src/main/kotlin/g0101_0200/s0190_reverse_bits/Solution.kt)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer, Algorithm_I_Day_14_Bit_Manipulation, Udemy_Bit_Manipulation | 198 | 81.82
15771577
| 0189 |[Rotate Array](src/main/kotlin/g0101_0200/s0189_rotate_array/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Algorithm_I_Day_2_Two_Pointers, Udemy_Arrays | 483 | 86.95
15781578
| 0188 |[Best Time to Buy and Sell Stock IV](src/main/kotlin/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/Solution.kt)| Hard | Array, Dynamic_Programming | 293 | 68.31
15791579
| 0187 |[Repeated DNA Sequences](src/main/kotlin/g0101_0200/s0187_repeated_dna_sequences/Solution.kt)| Medium | String, Hash_Table, Bit_Manipulation, Sliding_Window, Hash_Function, Rolling_Hash, Data_Structure_II_Day_9_String, Udemy_Strings | 319 | 79.03

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ repositories {
1515

1616
dependencies {
1717
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10")
18-
testImplementation("org.junit.jupiter:junit-jupiter-api:[5.9.0,)")
19-
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:[5.9.0,)")
18+
testImplementation("org.junit.jupiter:junit-jupiter-api:[5.9.1,)")
19+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:[5.9.1,)")
2020
testImplementation("org.hamcrest:hamcrest-core:[2.2,)")
2121
testImplementation("org.zapodot:embedded-db-junit-jupiter:[2.1.0,)")
2222
}

src/main/kotlin/g0101_0200/s0190_reverse_bits/Solution.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package g0101_0200.s0190_reverse_bits
44
// #Algorithm_I_Day_14_Bit_Manipulation #Udemy_Bit_Manipulation
55
// #2022_10_18_Time_198_ms_(81.82%)_Space_32.8_MB_(73.86%)
66

7+
@Suppress("NAME_SHADOWING")
78
class Solution {
89
// you need treat n as an unsigned value
910
fun reverseBits(n: Int): Int {
Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,32 @@
1-
189\. Rotate Array
1+
190\. Reverse Bits
22

3-
Medium
3+
Easy
44

5-
Given an array, rotate the array to the right by `k` steps, where `k` is non-negative.
5+
Reverse bits of a given 32 bits unsigned integer.
66

7-
**Example 1:**
8-
9-
**Input:** nums = [1,2,3,4,5,6,7], k = 3
7+
**Note:**
108

11-
**Output:** [5,6,7,1,2,3,4]
9+
* 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.
10+
* In Java, the compiler represents the signed integers using [2's complement notation](https://en.wikipedia.org/wiki/Two%27s_complement). Therefore, in **Example 2** above, the input represents the signed integer `-3` and the output represents the signed integer `-1073741825`.
1211

13-
**Explanation:**
12+
**Example 1:**
1413

15-
rotate 1 steps to the right: [7,1,2,3,4,5,6]
14+
**Input:** n = 00000010100101000001111010011100
1615

17-
rotate 2 steps to the right: [6,7,1,2,3,4,5]
16+
**Output:** 964176192 (00111001011110000010100101000000)
1817

19-
rotate 3 steps to the right: [5,6,7,1,2,3,4]
18+
**Explanation:** The input binary string **00000010100101000001111010011100** represents the unsigned integer 43261596, so return 964176192 which its binary representation is **00111001011110000010100101000000**.
2019

2120
**Example 2:**
2221

23-
**Input:** nums = [-1,-100,3,99], k = 2
22+
**Input:** n = 11111111111111111111111111111101
2423

25-
**Output:** [3,99,-1,-100]
24+
**Output:** 3221225471 (10111111111111111111111111111111)
2625

27-
**Explanation:**
28-
29-
rotate 1 steps to the right: [99,-1,-100,3]
30-
31-
rotate 2 steps to the right: [3,99,-1,-100]
26+
**Explanation:** The input binary string **11111111111111111111111111111101** represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is **10111111111111111111111111111111**.
3227

3328
**Constraints:**
3429

35-
* <code>1 <= nums.length <= 10<sup>5</sup></code>
36-
* <code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code>
37-
* <code>0 <= k <= 10<sup>5</sup></code>
38-
39-
**Follow up:**
30+
* The input must be a **binary string** of length `32`
4031

41-
* Try to come up with as many solutions as you can. There are at least **three** different ways to solve this problem.
42-
* Could you do it in-place with `O(1)` extra space?
32+
**Follow up:** If this function is called many times, how would you optimize it?

0 commit comments

Comments
 (0)