GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode/java/009_Palindrome_Number.java at master · iamsathish/leetcode

Expand file tree

/

009_Palindrome_Number.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
63 lines (60 loc) · 1.36 KB
/

009_Palindrome_Number.java

Copy path

File metadata and controls

63 lines (60 loc) · 1.36 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class Solution {
public boolean isPalindrome(int x) {
if (x < 0)
return false;
int temp = x;
int len = 0;
while (temp != 0) {
temp /= 10;
len ++;
}
temp = x;
int left, right;
for (int i = 0; i < len / 2; i++) {
right = temp % 10;
left = temp / (int) Math.pow(10, len - 2 * i - 1);
left = left % 10;
if (left != right)
return false;
temp /= 10;
}
return true;
}
// Leetcode book
public boolean isPalindrome(int x) {
if (x < 0) return false;
int div = 1;
while ( x / div >= 10) {
div *= 10;
}
while (x !=0) {
int l = x / div;
int r = x % 10;
if (l != r) return false;
// Remove left and right number
x = (x % div) / 10;
div /= 100;
}
return true;
}
}
// simpler code
class Solution {
public boolean isPalindrome(int x) {
int r,s=0,number=x;
if(number<0){
return false;
}
while (number!=0){
r=number%10;
s= s*10 +r;
number/=10;
}
if (s==x){
return true;
}
else {
return false;
}
}
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.