Skip to main content

The problem: Palindrome: Implement a function to check if a linked list is a palindrome

If it's a palindrome, the list must be the same backwards and forwards

Below is the code I wrote,:

  def isPalindrome[A](list:List[A]):Boolean= (list.head, list.last)match{
    case (a,b) if a==b&&list.size>2 => isPadorom[A]isPalindrome[A](list.tail.dropRight(1))
    case (a,b) if a==b&&list.size<=2 => true
    case (a,b) if a!=b =>false
  }

May I know is there any way to improve it?

The problem: Palindrome: Implement a function to check if a linked list is a palindrome

If it's a palindrome, the list must be the same backwards and forwards

Below is the code I wrote,

  def isPalindrome[A](list:List[A]):Boolean= (list.head, list.last)match{
    case (a,b) if a==b&&list.size>2 => isPadorom[A](list.tail.dropRight(1))
    case (a,b) if a==b&&list.size<=2 => true
    case (a,b) if a!=b =>false
  }

May I know is there any way to improve it?

The problem: Palindrome: Implement a function to check if a linked list is a palindrome

If it's a palindrome, the list must be the same backwards and forwards

Below is the code I wrote:

  def isPalindrome[A](list:List[A]):Boolean= (list.head, list.last)match{
    case (a,b) if a==b&&list.size>2 => isPalindrome[A](list.tail.dropRight(1))
    case (a,b) if a==b&&list.size<=2 => true
    case (a,b) if a!=b =>false
  }

May I know is there any way to improve it?

added 3 characters in body
Source Link

The problem: Palindrome: Implement a function to check if a linked list is a palindrome

If it's a palindrome, the list must be the same backwards and forwards

Below is the code I wrote,

  def isPadorom[A]isPalindrome[A](list:List[A]):Boolean= (list.head, list.last)match{
    case (a,b) if a==b&&list.size>2 => isPadorom[A](list.tail.dropRight(1))
    case (a,b) if a==b&&list.size<=2 => true
    case (a,b) if a!=b =>false
  }

May I know is there any way to improve it?

The problem: Palindrome: Implement a function to check if a linked list is a palindrome

If it's a palindrome, the list must be the same backwards and forwards

Below is the code I wrote,

  def isPadorom[A](list:List[A]):Boolean= (list.head, list.last)match{
    case (a,b) if a==b&&list.size>2 => isPadorom[A](list.tail.dropRight(1))
    case (a,b) if a==b&&list.size<=2 => true
    case (a,b) if a!=b =>false
  }

May I know is there any way to improve it?

The problem: Palindrome: Implement a function to check if a linked list is a palindrome

If it's a palindrome, the list must be the same backwards and forwards

Below is the code I wrote,

  def isPalindrome[A](list:List[A]):Boolean= (list.head, list.last)match{
    case (a,b) if a==b&&list.size>2 => isPadorom[A](list.tail.dropRight(1))
    case (a,b) if a==b&&list.size<=2 => true
    case (a,b) if a!=b =>false
  }

May I know is there any way to improve it?

added 75 characters in body
Source Link

The problem: Palindrome: Implement a function to check if a linked list is a palindrome

If it's a palindrome, the list must be the same backwards and forwards

Below is the code I wrote,

  def isPadorom[A](list:List[A]):Boolean= (list.head, list.last)match{
    case (a,b) if a==b&&list.size>2 => isPadorom[A](list.tail.dropRight(1))
    case (a,b) if a==b&&list.size<=2 => true
    case (a,b) if a!=b =>false
  }

May I know is there any way to improve it?

The problem: Palindrome: Implement a function to check if a linked list is a palindrome

Below is the code I wrote,

  def isPadorom[A](list:List[A]):Boolean= (list.head, list.last)match{
    case (a,b) if a==b&&list.size>2 => isPadorom[A](list.tail.dropRight(1))
    case (a,b) if a==b&&list.size<=2 => true
    case (a,b) if a!=b =>false
  }

May I know is there any way to improve it?

The problem: Palindrome: Implement a function to check if a linked list is a palindrome

If it's a palindrome, the list must be the same backwards and forwards

Below is the code I wrote,

  def isPadorom[A](list:List[A]):Boolean= (list.head, list.last)match{
    case (a,b) if a==b&&list.size>2 => isPadorom[A](list.tail.dropRight(1))
    case (a,b) if a==b&&list.size<=2 => true
    case (a,b) if a!=b =>false
  }

May I know is there any way to improve it?

deleted 11 characters in body; edited tags; edited title
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
Loading
Source Link
Loading