Skip to content

Commit 6aa4346

Browse files
committed
issue #17 234-Done
1 parent 59ea657 commit 6aa4346

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package leetcodeEasyLevel;
2+
3+
public class _0234PalindromeLinkedList {
4+
protected ListNode reverse(ListNode head){
5+
if (head == null || head.next == null)
6+
return head;
7+
ListNode next = reverse(head.next);
8+
head.next.next = head;
9+
head.next = null;
10+
return next;
11+
}
12+
public boolean isPalindrome(ListNode head) {
13+
ListNode fast = head, slow = head;
14+
15+
while(fast != null && fast.next != null){
16+
fast = fast.next.next;
17+
slow = slow.next;
18+
}
19+
20+
fast = head;
21+
slow = reverse(slow);
22+
23+
while (fast != null && slow != null){
24+
if (fast.val != slow.val)
25+
return false;
26+
fast = fast.next;
27+
slow = slow.next;
28+
}
29+
return true;
30+
}
31+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package leetcodeEasyLevel;
2+
3+
public class _0242ValidAnagram {
4+
public static boolean isAnagram(String s, String t) {
5+
6+
return true;
7+
}
8+
9+
public static void main(String[] args) {
10+
System.out.println(isAnagram("anagram","nagaram")); //=>true
11+
System.out.println(isAnagram("rat","car")); //=>false
12+
13+
}
14+
15+
}

0 commit comments

Comments
 (0)