每天刷一道牛客题霸-第23天- 判断一个链表是否为回文结构

题目

https://www.nowcoder.com/practice/3fed228444e740c8be66232ce8b87c2f?tpId=190&&tqId=35218&rp=1&ru=/ta/job-code-high-rd&qru=/ta/job-code-high-rd/question-ranking

import java.util.*;

/*
 * public class ListNode {
 *   int val;
 *   ListNode next = null;
 * }
 */

public class Solution {
    /**
     * 
     * @param head ListNode类 the head
     * @return bool布尔型
     */
    public boolean isPail (ListNode head) {
        // write code here
        if(head == null){
            return true;          
        }
        StringBuilder stringList = new StringBuilder();
        while(head != null){
            stringList.append(String.valueOf(head.val));
            head = head.next;
        }
        String r = stringList.toString();
        String s = stringList.reverse().toString(); 
        return s.equals(r);
    }
}
#牛客题霸##题解#
全部评论
点赞 回复 分享
发布于 2021-01-05 19:21

相关推荐

无一技之长怎么办:别去右边,售前,实施,需求分析一起,这是把人当牛马用啊,快跑,这些岗位天花板很低的
点赞 评论 收藏
分享
02-24 10:34
门头沟学院 Java
已注销:之前发最美的女孩基本爱答不理,发最帅的hr终于有反馈了,女孩子也要自信起来
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
正在热议
更多
牛客网
牛客企业服务