We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4804888 commit 26cf7aeCopy full SHA for 26cf7ae
src/main/java/com/fishercoder/solutions/_234.java
@@ -80,4 +80,24 @@ public boolean isPalindrome(ListNode head) {
80
}
81
82
83
+ public static class Solution3 {
84
+ /**
85
+ * O(n) time
86
+ * O(n) space
87
+ */
88
+ public boolean isPalindrome(ListNode head) {
89
+ List<Integer> list = new ArrayList<>();
90
+ while (head != null) {
91
+ list.add(head.val);
92
+ head = head.next;
93
+ }
94
+ for (int i = 0, j = list.size() - 1; i <= j; i++, j--) {
95
+ if (list.get(i) != list.get(j)) {
96
+ return false;
97
98
99
+ return true;
100
101
102
+
103
0 commit comments