Skip to content

Commit dbb76a9

Browse files
committed
Expand benchmarking and optimize problem 9
1 parent 83a24e1 commit dbb76a9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

9.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
)
77

88
func isPalindrome(x int) bool {
9+
if x < 0 {
10+
return false
11+
}
12+
913
x_str := strconv.Itoa(x)
1014
length_of_x := len(x_str)
1115

9_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ func TestIsPalindrome3(t *testing.T) {
3232
}
3333

3434
func BenchmarkIsPalindrome(b *testing.B) {
35-
for i := 0; i < b.N; i++ {
35+
midpoint := b.N / 2
36+
37+
for i := -midpoint; i < midpoint; i++ {
3638
isPalindrome(b.N)
3739
}
3840
}

0 commit comments

Comments
 (0)