File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ package leetcode
2
+
3
+ /*
4
+ * @lc app=leetcode id=9 lang=golang
5
+ *
6
+ * [9] Palindrome Number
7
+ */
8
+
9
+ // @lc code=start
10
+ func isPalindrome (x int ) bool {
11
+ if x < 0 {
12
+ return false
13
+ }
14
+ if x < 10 {
15
+ return true
16
+ }
17
+ if x % 10 == 0 {
18
+ return false
19
+ }
20
+ var y int
21
+ for x > y {
22
+ y = y * 10 + x % 10
23
+ x = x / 10
24
+ println (x , y )
25
+ }
26
+ return x == y || x == y / 10
27
+ }
28
+
29
+ // @lc code=end
Original file line number Diff line number Diff line change
1
+ /*
2
+ * @lc app=leetcode id=9 lang=javascript
3
+ *
4
+ * [9] Palindrome Number
5
+ */
6
+
7
+ // @lc code=start
8
+ function isPalindrome ( x ) {
9
+ if ( x < 0 ) {
10
+ return false ;
11
+ }
12
+
13
+ let num = x ;
14
+ let reverse = 0 ;
15
+
16
+ while ( num > 0 ) {
17
+ reverse = reverse * 10 + ( num % 10 ) ;
18
+ num = Math . floor ( num / 10 ) ;
19
+ }
20
+
21
+ return reverse === x ;
22
+ }
23
+
24
+ // @lc code=end
You can’t perform that action at this time.
0 commit comments