update at 2022-12-03 23:27:52 by ehlxr

This commit is contained in:
ehlxr 2022-12-03 23:27:52 +08:00
parent c1da2bd955
commit f251d5601a
2 changed files with 96 additions and 3 deletions

View File

@ -0,0 +1,85 @@
/*
* The MIT License (MIT)
*
* Copyright © 2022 xrv <xrv@live.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.ehlxr.algorithm.linkedlist;
/**
* @author ehlxr
* @since 2022-12-03 23:11.
*/
public class Palindrome {
public static class ListNode {
int val;
ListNode next;
ListNode() {
}
ListNode(int val) {
this.val = val;
}
ListNode(int val, ListNode next) {
this.val = val;
this.next = next;
}
@Override
public String toString() {
return "ListNode{" +
"val=" + val +
", next=" + next +
'}';
}
}
public static boolean isPalindrome(ListNode head) {
if (head == null) {
return false;
}
ListNode slow = head;
ListNode fast = head;
while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
}
System.out.println("中位节点:" + slow);
return false;
}
public static void main(String[] args) {
ListNode head = new ListNode(1);
head.next = new ListNode(2);
head.next.next = new ListNode(3);
head.next.next.next = new ListNode(4);
head.next.next.next.next = new ListNode(5);
// head.next.next.next.next.next = new ListNode(6);
System.out.println(head);
isPalindrome(head);
}
}

View File

@ -24,6 +24,11 @@
package io.github.ehlxr; package io.github.ehlxr;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* @author ehlxr * @author ehlxr
* @since 2022-01-17 06:31. * @since 2022-01-17 06:31.
@ -31,12 +36,15 @@ package io.github.ehlxr;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
int[][] ns = { int[][] ns = {
{ 1, 2, 3, 4 }, {1, 2, 3, 4},
{ 5, 6, 7, 8 }, {5, 6, 7, 8},
{ 9, 10, 11, 12 } {9, 10, 11, 12}
}; };
System.out.println(ns.length); // 3 System.out.println(ns.length); // 3
System.out.println(ns[0].length); // 4 System.out.println(ns[0].length); // 4
System.out.println(ns[2][2]); // 11 System.out.println(ns[2][2]); // 11
List<String> collect = Stream.of("111", "wwwdddd", "dddddd", "12").filter(x -> x.length() > 3).collect(Collectors.toList());
} }
} }