From f251d5601a7952df5bd0e61ef48827a6f23db239 Mon Sep 17 00:00:00 2001 From: ehlxr Date: Sat, 3 Dec 2022 23:27:52 +0800 Subject: [PATCH] update at 2022-12-03 23:27:52 by ehlxr --- .../algorithm/linkedlist/Palindrome.java | 85 +++++++++++++++++++ .../src/main/java/io/github/ehlxr/Main.java | 14 ++- 2 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 budd-common/src/main/java/io/github/ehlxr/algorithm/linkedlist/Palindrome.java diff --git a/budd-common/src/main/java/io/github/ehlxr/algorithm/linkedlist/Palindrome.java b/budd-common/src/main/java/io/github/ehlxr/algorithm/linkedlist/Palindrome.java new file mode 100644 index 0000000..7c58f0d --- /dev/null +++ b/budd-common/src/main/java/io/github/ehlxr/algorithm/linkedlist/Palindrome.java @@ -0,0 +1,85 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 xrv + * + * 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); + } +} diff --git a/budd-demo/src/main/java/io/github/ehlxr/Main.java b/budd-demo/src/main/java/io/github/ehlxr/Main.java index 781b9d6..2db3943 100644 --- a/budd-demo/src/main/java/io/github/ehlxr/Main.java +++ b/budd-demo/src/main/java/io/github/ehlxr/Main.java @@ -24,6 +24,11 @@ package io.github.ehlxr; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + /** * @author ehlxr * @since 2022-01-17 06:31. @@ -31,12 +36,15 @@ package io.github.ehlxr; public class Main { public static void main(String[] args) { int[][] ns = { - { 1, 2, 3, 4 }, - { 5, 6, 7, 8 }, - { 9, 10, 11, 12 } + {1, 2, 3, 4}, + {5, 6, 7, 8}, + {9, 10, 11, 12} }; System.out.println(ns.length); // 3 System.out.println(ns[0].length); // 4 System.out.println(ns[2][2]); // 11 + + + List collect = Stream.of("111", "wwwdddd", "dddddd", "12").filter(x -> x.length() > 3).collect(Collectors.toList()); } }