Skip to content

Instantly share code, notes, and snippets.

@mumunuu
Created February 28, 2021 16:55
Show Gist options
  • Save mumunuu/a3affdc5365ef92e69dc4d0fabd2c8d7 to your computer and use it in GitHub Desktop.
Save mumunuu/a3affdc5365ef92e69dc4d0fabd2c8d7 to your computer and use it in GitHub Desktop.
algorithm(leetcode) Palindrome Linked List
func isPalindrome(head *ListNode) bool {
//돌면서 다 담아주고
tmpArr := make([]int, 0)
for head != nil {
tmpArr = append(tmpArr, head.Val)
head = head.Next
}
// 1/2만 돌면서 비교하면 됨
for i:=0; i<len(tmpArr)/2; i++ {
if tmpArr[i] != tmpArr[len(tmpArr)-1-i] {
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment