Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc232b08

Browse files
author
Sathish Babu
committed
✨ Added solution to 717
1 parent74cf4bf commitc232b08

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

‎src/0717.1-bit-and-2-bit-Characters/README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,28 @@
55
66
##Description
77

8+
We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11).
9+
10+
Now given a string represented by several bits. Return whether the last character must be a one-bit character or not. The given string will always end with a zero.
11+
812
**Example 1:**
913

1014
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
15+
Input:
16+
bits = [1, 0, 0]
17+
Output: True
18+
Explanation:
19+
The only way to decode it is two-bit character and one-bit character. So the last character is one-bit character.
20+
```
21+
22+
**Example 2:**
23+
24+
```
25+
Input:
26+
bits = [1, 1, 1, 0]
27+
Output: False
28+
Explanation:
29+
The only way to decode it is two-bit character and two-bit character. So the last character is NOT one-bit character.
1330
```
1431

1532
##题意
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
package Solution
22

3-
funcSolution(xbool)bool {
4-
returnx
3+
funcSolution(bits []int)bool {
4+
n:=len(bits)
5+
ifn==1 {
6+
returntrue
7+
}
8+
fori:=0;i<n; {
9+
ifi==n-1 {
10+
returntrue
11+
}
12+
ifbits[i]==0 {
13+
i++
14+
}else {
15+
i+=2
16+
}
17+
}
18+
returnfalse
519
}

‎src/0717.1-bit-and-2-bit-Characters/Solution_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ func TestSolution(t *testing.T) {
1010
//测试用例
1111
cases:= []struct {
1212
namestring
13-
inputsbool
13+
inputs[]int
1414
expectbool
1515
}{
16-
{"TestCase",true,true},
17-
{"TestCase",true,true},
18-
{"TestCase",false,false},
16+
{"TestCase", []int{0},true},
17+
{"TestCase", []int{1,0,0},true},
18+
{"TestCase", []int{1,1,1,0},false},
19+
{"TestCase", []int{0,1,1,0},true},
1920
}
2021

2122
//开始测试

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp