添加新题目

This commit is contained in:
2025-08-23 23:09:54 +08:00
parent 62034548cc
commit 70fe6d292c
8 changed files with 260 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
package main
type ListNode struct {
Val int
Next *ListNode
}
func main() {
}
func isPalindrome(head *ListNode) bool {
numlist := make([]int, 0)
for head != nil {
numlist = append(numlist, head.Val)
head = head.Next
}
if len(numlist) == 1 {
return true
}
left := len(numlist)/2 - 1
right := left + 1
if len(numlist)%2 != 0 {
left = len(numlist) / 2
right = left
} else {
left = len(numlist)/2 - 1
right = left + 1
}
for left >= 0 {
if numlist[left] == numlist[right] {
left--
right++
} else {
return false
}
}
return true
}