Created
February 28, 2021 16:55
-
-
Save mumunuu/a3affdc5365ef92e69dc4d0fabd2c8d7 to your computer and use it in GitHub Desktop.
algorithm(leetcode) Palindrome Linked List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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