Category : palindrome

I have found a recursive solution to check whether a linked list is a palindrome: def isPalindrome(self, head: ListNode) -> bool: self.front_pointer = head def recursively_check(head): if head: if not recursively_check(head.next): return False if self.front_pointer.val != head.val: return False self.front_pointer = self.front_pointer.next return True return recursively_check() After the ‘if head’ statement: Why are we returning ..

Read more

this is my code, but there is still an error, I will make the application determine whether the sentence is a palindrome or not a palindrome from tkinter import * class MembuatKolomTeks(Frame) : def __init__(self, master) : self.buatTeks() self.buatKolom(master) self.buatTombol() def buatTeks(self): Label(text="Inputkan Kalimat").grid(row=0) def buatKolom(self, master): self.kolom1 = Entry(master) self.kolom1.grid(row=0, column=1) def buatTombol(self): Button(text=’Hasil’, ..

Read more

def is_palindromic_linked_list(head): if head is None or head.next is None: return True slow = head fast = head while fast is not None and fast.next is not None: fast = fast.next.next slow = slow.next head_second_half = reverse(slow) #6, 4, 2 => 2, 4, 6 copy_head_second_half = head_second_half #<——HERE: copied linkedlist while (head is not None ..

Read more

The is_palindrome function checks if a string is a palindrome. A palindrome is a string that can be equally read from left to right or right to left, omitting blank spaces, and ignoring capitalization. Examples of palindromes are words like kayak and radar, and phrases like "Never Odd or Even". Fill in the blanks in ..

Read more

I am trying to find the longest Palidromic Substring of a given string, LeetCode problem. I am getting a lesser runtime for expanding centers even though its time complexity is N**2 and manachers is N. What mistake am I making? ”’ Manachers Algorithm O(N) —> runtime 2000ms class Solution(object): def addhashspace(self,s: str) -> str: t ..

Read more