Skip to content

Commit 3f23251

Browse files
solves one bit and two bit array
1 parent 4ece22c commit 3f23251

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

Diff for: README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# LeetCode Algorithms
22

3-
![problems-solved](https://img.shields.io/badge/Problems%20Solved-175/2081-1f425f.svg)
4-
![problems-solved-java](https://img.shields.io/badge/Java-175/2081-1abc9c.svg)
5-
![problems-solved-python](https://img.shields.io/badge/Python-175/2081-1abc9c.svg)
3+
![problems-solved](https://img.shields.io/badge/Problems%20Solved-176/2081-1f425f.svg)
4+
![problems-solved-java](https://img.shields.io/badge/Java-176/2081-1abc9c.svg)
5+
![problems-solved-python](https://img.shields.io/badge/Python-176/2081-1abc9c.svg)
66
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
77
[![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming)
88

@@ -197,7 +197,7 @@
197197
| 706 | [Design HashMap](https://leetcode.com/problems/design-hashmap) | [![Java](assets/java.png)](src/DesignHashMap.java) [![Python](assets/python.png)](python/design_hash_map.py) |
198198
| 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case) | [![Java](assets/java.png)](src/ToLowerCase.java) [![Python](assets/python.png)](python/to_lower_case.py) |
199199
| 716 | [Max Stack](https://leetcode.com/problems/max-stack) | |
200-
| 717 | [1-bit and 2-bit Characters](https://leetcode.com/problems/1-bit-and-2-bit-characters) | |
200+
| 717 | [1-bit and 2-bit Characters](https://leetcode.com/problems/1-bit-and-2-bit-characters) | [![Java](assets/java.png)](src/OneBitAndTwoBitCharacters.java) [![Python](assets/python.png)](python/one_bit_and_two_bit_characters.py) |
201201
| 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary) | |
202202
| 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index) | |
203203
| 728 | [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers) | |

Diff for: python/one_bit_and_two_bit_characters.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def isOneBitCharacter(self, bits: List[int]) -> bool:
6+
count = 0
7+
index = len(bits) - 2
8+
while index >= 0 and bits[index] != 0:
9+
if bits[index] == 1: count += 1
10+
index -= 1
11+
return count % 2 == 0

Diff for: src/OneBitAndTwoBitCharacters.java

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class OneBitAndTwoBitCharacters {
2+
public boolean isOneBitCharacter(int[] bits) {
3+
for (int index = 0 ; index < bits.length ; index++) {
4+
if (bits[index] == 1) {
5+
index++;
6+
} else if (bits[index] == 0 && index == bits.length - 1) {
7+
return true;
8+
}
9+
}
10+
return false;
11+
}
12+
}

0 commit comments

Comments
 (0)