Skip to content

Commit 7aa77fc

Browse files
authored
Create Palindrome-number.java and Updated README.md (#139)
* update README file with Palindrome-number problem * create palindrome-number.java * update README file with Path-Sum problem * create path-sum.java
1 parent f857240 commit 7aa77fc

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

Java/palindrome-number.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public boolean isPalindrome(int x) {
3+
String _x = x+""; // integer convert string
4+
String rev = ""; // store reverse
5+
int i = 0;
6+
for(i = _x.length()-1; i>=0; i--){
7+
rev += _x.charAt(i);
8+
}
9+
10+
if(_x.compareTo(rev) == 0){
11+
// correct
12+
return true;
13+
}
14+
else{
15+
return false;
16+
}
17+
18+
}
19+
}

Java/path-sum.java

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* int val;
5+
* TreeNode left;
6+
* TreeNode right;
7+
* TreeNode() {}
8+
* TreeNode(int val) { this.val = val; }
9+
* TreeNode(int val, TreeNode left, TreeNode right) {
10+
* this.val = val;
11+
* this.left = left;
12+
* this.right = right;
13+
* }
14+
* }
15+
*/
16+
class Solution {
17+
public boolean hasPathSum(TreeNode root, int sum) {
18+
if(root == null){
19+
// exception
20+
return false;
21+
}
22+
if(root.left == null && root.right == null){
23+
if(sum == root.val){
24+
return true;
25+
}
26+
return false;
27+
}
28+
else{
29+
boolean left = false;
30+
boolean right = false;
31+
if(root.left != null){
32+
left = hasPathSum(root.left, sum-root.val);
33+
}
34+
if(root.right != null){
35+
right = hasPathSum(root.right, sum-root.val);
36+
}
37+
return left||right;
38+
}
39+
}
40+
}

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
159159
| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/) | [Java](./Java/max-nesting-depth-parentheses.java) | _O(n)_ | _O(1)_ | Easy | | |
160160
| 1374 | [Generate a String With Characters That Have Odd Counts](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts/) | [Java](./Java/generate-a-string-with-characters-that-have-odd-counts.java) | _O(n)_ | _O(1)_ | Easy | | |
161161
| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings/) | [Java](./Java/buddy-strings.java) | _O(n)_ | _O(1)_ | Easy | | |
162+
| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Java](./Java/palindrome-number.java) | _O(n)_ | _O(1)_ | Easy | | |
162163
<br/>
163164
<div align="right">
164165
<b><a href="#algorithms">⬆️ Back to Top</a></b>
@@ -327,6 +328,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
327328
| ---- | ------------------------------------------------------------------------------------------- | -------------------------------------------------- | ----------- | ----------- | ---------- | --- | ---- |
328329
| 1463 | [Cherry Pickup II](https://leetcode.com/problems/cherry-pickup-ii/) | [C++](./C++/Cherry-Pickup-II.cpp) | _O(n \* m)_ | _O(n \* m)_ | Hard | DFS | |
329330
| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [python](./Python/maximum-depth-of-binary-tree.py) | _O(n)_ | _O(n)_ | Easy | DFS | |
331+
| 112 | [Path Sum](https://leetcode.com/problems/path-sum/) | [Java](./Java/path-sum.java) | _O(n)_ | _O(n)_ | Easy | DFS | |
330332

331333
<br/>
332334
<div align="right">

0 commit comments

Comments
 (0)