Skip to content

Commit a6c9f21

Browse files
committed
2022-06-22 update: added "1-bit and 2-bit Characters"
1 parent 9939032 commit a6c9f21

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.smlnskgmail.jaman.leetcodejava.easy;
2+
3+
// https://leetcode.com/problems/1-bit-and-2-bit-characters/
4+
public class OneBitAndTwoBitCharacters {
5+
6+
private final int[] input;
7+
8+
public OneBitAndTwoBitCharacters(int[] input) {
9+
this.input = input;
10+
}
11+
12+
public boolean solution() {
13+
int pos = 0;
14+
while (pos < input.length - 1) {
15+
pos += input[pos] == 1 ? 2 : 1;
16+
}
17+
return pos == input.length - 1;
18+
}
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.smlnskgmail.jaman.leetcodejava.easy;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertTrue;
6+
7+
public class OneBitAndTwoBitCharactersTest {
8+
9+
@Test
10+
public void defaultTest() {
11+
assertTrue(new OneBitAndTwoBitCharacters(new int[]{1, 0, 0}).solution());
12+
}
13+
14+
}

0 commit comments

Comments
 (0)