File tree 5 files changed +75
-0
lines changed
5 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 3
3
## go solution
4
4
- [ 1.two-sum] ( ./src/1-TwoSum/1-two-sum.go )
5
5
- [ 7.reverse-integer] ( ./src/7-ReverseInteger/7-reverse-integer.go )
6
+ - [ 9.palindrome-number] ( ./src/9-PalindromeNumbe/palindrome_num.go )
6
7
- [ 14.longest-common-prefix] ( ./src/14-LongestCommonPrefix/14_longest_common_prefix.go )
7
8
- [ 27.remove-element] ( ./src/27-RemoveElement/rm_ele.go )
8
9
- [ 35.search-insert-position] ( ./src/35-SearchInsertPosition/search_insert_position.go )
Original file line number Diff line number Diff line change
1
+ package cs
2
+
3
+ // ClimbStairs calculate n steps to reach the top
4
+ // You are climbing a stair case. It takes n steps to reach to the top.
5
+ // Each time you can either climb 1 or 2 steps.
6
+ // In how many distinct ways can you climb to the top?
7
+ // Note: Given n will be a positive integer.
8
+ // see more from https://leetcode.com/problems/climbing-stairs/description/
9
+ func ClimbStairs (n int ) int {
10
+
11
+ return count
12
+ }
Original file line number Diff line number Diff line change
1
+ package cs
2
+
3
+ import (
4
+ "testing"
5
+ )
6
+
7
+ func TestClimbStairs (t * testing.T ) {
8
+ var n = 6
9
+ nums := ClimbStairs (n )
10
+ if nums != 8 {
11
+ t .Error ("fail" )
12
+ }
13
+ t .Log (nums )
14
+ }
Original file line number Diff line number Diff line change
1
+ package pn
2
+
3
+ import (
4
+ "strconv"
5
+ "strings"
6
+ )
7
+
8
+ // PalindromeNumber Determine whether an integer is a palindrome.
9
+ // An integer is a palindrome when it reads the same backward as forward.
10
+
11
+ func PalindromeNumber (x int ) bool {
12
+ if x < 0 {
13
+ return false
14
+ }
15
+ arr := strings .Split (strconv .Itoa (x ), "" )
16
+ lens := len (arr )
17
+ for k , v := range arr {
18
+ if k <= (lens / 2 ) && v != arr [lens - 1 - k ] {
19
+ return false
20
+ }
21
+ }
22
+ return true
23
+ }
Original file line number Diff line number Diff line change
1
+ package pn
2
+
3
+ import (
4
+ "testing"
5
+ )
6
+
7
+ func TestPalindromeNumber (t * testing.T ) {
8
+ var num = 343
9
+ if ok := PalindromeNumber (num ); ! ok {
10
+ t .Error (num , " is not a palindrome number. " )
11
+ }
12
+ t .Log (num )
13
+
14
+ num = 12345321
15
+ if ok := PalindromeNumber (num ); ! ok {
16
+ t .Error (num , " is not a palindrome number. " )
17
+ }
18
+ t .Log (num )
19
+
20
+ num = - 121
21
+ if ok := PalindromeNumber (num ); ! ok {
22
+ t .Error (num , " is not a palindrome number. " )
23
+ }
24
+ t .Log (num )
25
+ }
You can’t perform that action at this time.
0 commit comments