Skip to content

Commit 76c7bf8

Browse files
committed
update
1 parent 7287a19 commit 76c7bf8

File tree

4 files changed

+59
-7
lines changed

4 files changed

+59
-7
lines changed

src/main/java/com/leetcode/linkedlist/LinkedListTwo.java renamed to src/main/java/com/leetcode/linkedlist/MergeTwoList.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* merge two list
1010
*/
11-
public class LinkedListTwo {
11+
public class MergeTwoList {
1212

1313
public ListNode mergeTwoLists(ListNode head1, ListNode head2) {
1414
ArrayList<Integer> list = new ArrayList<Integer>();
@@ -26,8 +26,6 @@ public ListNode mergeTwoLists(ListNode head1, ListNode head2) {
2626
head2 = head2.next;
2727
}
2828
}
29-
30-
3129
ListNode head = Utils.buildList(list.stream().mapToInt(Integer::intValue).toArray());
3230
return head;
3331
}
@@ -37,7 +35,7 @@ public static void main(String[] args) {
3735
int[] arr1 = {1, 2, 4}, arr2 = {1, 3, 4};
3836
ListNode head1 = Utils.buildList(arr1);
3937
ListNode head2 = Utils.buildList(arr2);
40-
ListNode newHead = new LinkedListTwo().mergeTwoLists(head1, head2);
38+
ListNode newHead = new MergeTwoList().mergeTwoLists(head1, head2);
4139
while (newHead != null) {
4240
System.out.println(newHead.val);
4341
newHead = newHead.next;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.leetcode.linkedlist;
2+
3+
import com.leetcode.util.ListNode;
4+
5+
import java.util.List;
6+
import java.util.Stack;
7+
8+
public class ParlindromeList {
9+
10+
public boolean isPalindrome(ListNode head) {
11+
int len = 1;
12+
ListNode curnode = head;
13+
while(curnode.next != null){
14+
len++;
15+
curnode = curnode.next;
16+
}
17+
if(len % 2 == 1){
18+
return false;
19+
}else{
20+
int i = 0;
21+
curnode = head;
22+
Stack<Integer> stack = new Stack<Integer>();
23+
while( i < len / 2){
24+
stack.push(curnode.val);
25+
curnode = curnode.next;
26+
i++;
27+
}
28+
29+
while(i < len){
30+
Integer pop = stack.pop();
31+
if(pop != curnode.val){
32+
return false;
33+
}
34+
curnode = curnode.next;
35+
i++;
36+
}
37+
return true;
38+
}
39+
}
40+
41+
public static void main(String[] args) {
42+
ListNode node1 = new ListNode(1);
43+
ListNode node2 = new ListNode(2);
44+
ListNode node3 = new ListNode(2);
45+
ListNode node4 = new ListNode(1);
46+
node1.next = node2;
47+
node2.next = node3;
48+
node3.next = node4;
49+
50+
boolean b = new ParlindromeList().isPalindrome(node1);
51+
System.out.println(b);
52+
53+
}
54+
}

src/main/java/com/leetcode/matrix/MatrixOne.java renamed to src/main/java/com/leetcode/matrix/MatrixSetZero.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.ArrayList;
44

5-
public class MatrixOne {
5+
public class MatrixSetZero {
66

77
public void setZeroes(int[][] matrix) {
88

@@ -54,7 +54,7 @@ public static void main(String[] args) {
5454
//int[][] matrix = {{1,1,1},{1,0,1},{1,1,1}};
5555
// int[][] matrix = {{0,1,2,0},{3,4,5,2},{1,3,1,5}};
5656
int[][] matrix = {{1, 0}};
57-
new MatrixOne().setZeroes(matrix);
57+
new MatrixSetZero().setZeroes(matrix);
5858
for (int[] row : matrix) {
5959
System.out.print("[ ");
6060
for (int element : row) {

src/main/java/com/leetcode/slidingwindow/SlidingWindowOne.java renamed to src/main/java/com/leetcode/slidingwindow/LongestSubstr.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* name : longest substring without repeating characters.
66
*
77
*/
8-
public class SlidingWindowOne {
8+
public class LongestSubstr {
99

1010

1111
public static int lengthOfLongestSubstring(String s) {

0 commit comments

Comments
 (0)