Skip to content

Commit 1eb664f

Browse files
committed
fixed solution035 and removed git hook
1 parent c5fa18e commit 1eb664f

File tree

5 files changed

+5
-16
lines changed

5 files changed

+5
-16
lines changed

Makefile

-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,4 @@ fix: FORCE
2121
report: FORCE
2222
curl -s -d 'repo=github.com%2FTipsyPixie%2Fgo-daily-coding-problem' https://goreportcard.com/checks >/dev/null
2323

24-
hook: FORCE
25-
find 'hooks' -maxdepth 1 -type f -exec ln -s '../../{}' -t './.git/hooks' \;
26-
2724
precommit: fix analyze format test

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ Run `make test` to test the solutions.
1212
make test # test all
1313
```
1414

15-
`make hook` to install git hooks in `hooks` directory.
16-
1715
## Problems
1816

1917
Number | Difficulty | Asked By

hooks/pre-commit

-6
This file was deleted.

problem035/problem035.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package problem035
22

33
func partialSegregate(letter rune, in []rune) int {
44
leftIndex, rightIndex := 0, len(in)
5-
for leftIndex < rightIndex {
5+
for leftIndex <= rightIndex {
66
leftLetter := in[leftIndex]
77
if leftLetter == letter {
88
leftIndex++
@@ -14,12 +14,12 @@ func partialSegregate(letter rune, in []rune) int {
1414
in[leftIndex], in[rightIndex] = rightLetter, leftLetter
1515
}
1616
}
17-
return leftIndex + 1
17+
return leftIndex
1818
}
1919

2020
func Segregate(letters []rune) {
2121
letterTypes := []rune{'R', 'G', 'B'}
22-
for typeIndex, startingIndex := 0, 0; typeIndex < len(letterTypes) && startingIndex < len(letters); typeIndex++ {
23-
startingIndex = partialSegregate(letterTypes[typeIndex], letters[startingIndex:])
22+
for typeIndex, startingIndex := 0, 0; typeIndex < len(letterTypes)-1 && startingIndex < len(letters); typeIndex++ {
23+
startingIndex += partialSegregate(letterTypes[typeIndex], letters[startingIndex:])
2424
}
2525
}

problem035/problem035_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
func TestSegregate(t *testing.T) {
99
input := []rune{'G', 'B', 'R', 'R', 'B', 'R', 'G', 'R', 'R', 'B', 'G', 'R', 'B'}
1010
Segregate(input)
11-
if reflect.DeepEqual(input, []rune{'R', 'R', 'R', 'R', 'R', 'R', 'G', 'G', 'G', 'B', 'B', 'B'}) {
11+
if !reflect.DeepEqual(input, []rune{'R', 'R', 'R', 'R', 'R', 'R', 'G', 'G', 'G', 'B', 'B', 'B', 'B'}) {
1212
t.Fail()
1313
}
1414
}

0 commit comments

Comments
 (0)