Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 7563fcf

Browse files
committed
906 finish
1 parent 1d9917e commit 7563fcf

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
package problem0906
22

3+
import (
4+
"sort"
5+
"strconv"
6+
)
7+
8+
// square root of all superpalindrome
9+
var palindromes = []int{
10+
1, 2, 3,
11+
11, 22,
12+
101, 111, 121, 202, 212,
13+
1001, 1111, 2002,
14+
10001, 10101, 10201, 11011, 11111, 11211, 20002, 20102,
15+
100001, 101101, 110011, 111111, 200002,
16+
1000001, 1001001, 1002001, 1010101, 1011101, 1012101, 1100011, 1101011, 1102011, 1110111, 1111111, 2000002, 2001002,
17+
10000001, 10011001, 10100101, 10111101, 11000011, 11011011, 11100111, 11111111, 20000002,
18+
100000001, 100010001, 100020001, 100101001, 100111001, 100121001, 101000101, 101010101, 101020101, 101101101, 101111101, 110000011, 110010011, 110020011, 110101011, 110111011, 111000111, 111010111, 111101111, 111111111, 200000002, 200010002,
19+
}
20+
321
func superpalindromesInRange(L, R string) int {
22+
l, _ := strconv.Atoi(L)
23+
r, _ := strconv.Atoi(R)
24+
25+
li := sort.Search(len(palindromes), func(i int) bool {
26+
return l <= palindromes[i]*palindromes[i]
27+
})
28+
29+
ri := sort.Search(len(palindromes), func(i int) bool {
30+
return r <= palindromes[i]*palindromes[i]
31+
})
432

5-
return 0
33+
return ri - li
634
}

Algorithms/0906.super-palindromes/super-palindromes_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ var tcs = []struct {
1313
ans int
1414
}{
1515

16+
{
17+
"1020762146323",
18+
"142246798855636",
19+
17,
20+
},
21+
22+
{
23+
"398904669",
24+
"13479046850",
25+
6,
26+
},
27+
28+
{
29+
"1",
30+
"2",
31+
1,
32+
},
33+
1634
{
1735
"4",
1836
"1000",

0 commit comments

Comments
 (0)