题目
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);
}
}
全部评论
(1) 回帖