您的位置:首页 > 新闻 > 资讯 > 响应式网站代码_企业网站的在线推广方法有哪几种_百度广告联盟平台官网_百度下载链接

响应式网站代码_企业网站的在线推广方法有哪几种_百度广告联盟平台官网_百度下载链接

2025/3/10 23:16:23 来源:https://blog.csdn.net/yang_brother/article/details/142371819  浏览:    关键词:响应式网站代码_企业网站的在线推广方法有哪几种_百度广告联盟平台官网_百度下载链接
响应式网站代码_企业网站的在线推广方法有哪几种_百度广告联盟平台官网_百度下载链接

题目:LCR 027


解法一:快慢指针 + 反转链表

  1. 取中间节点的下一节点,即为链表后半部分。当链表为(1,2,3,4,null)时,取节点3。当链表为(1,2,3,4,5,null)时,取节点4
  2. 反转后半部分链表
  3. 前半链表与后半链表同时开始向后遍历,验证回文串
  4. 恢复链表
    public boolean isPalindrome(ListNode head) {if (head == null || head.next == null) return true;ListNode slow = head, fast = head;while (fast.next != null && fast.next.next != null) {slow = slow.next;fast = fast.next.next;}ListNode reverse = reverseList(slow.next), node1 = head, node2 = reverse;while (node2 != null) {if (node2.val != node1.val) return false;node2 = node2.next;node1 = node1.next;}reverseList(reverse);return true;}public ListNode reverseList(ListNode head) {ListNode prev = null, curr = head, next;while (curr != null) {next = curr.next;curr.next = prev;prev = curr;curr = next;}return prev;

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com