leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 92277f1ab4946d5f977afe2d85fa0197eab06a3a
parent f8c8338ce72d74b9d3cc453625e198259ea5fdd5
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Fri, 21 Apr 2023 01:19:01 -0500

Completed valid palindrome problem with dart

Diffstat:
Avalid-palindrome/valid-palindrome.dart | 25+++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)

diff --git a/valid-palindrome/valid-palindrome.dart b/valid-palindrome/valid-palindrome.dart @@ -0,0 +1,25 @@ +//Check to see if the string is a palindrome +//don't take into account spaces punctuation or caps. +//Time complexity is O(n) where n is the length of s. +//Runtime: 288ms Beats: 89.92% +//Memory: 144.5MB Beats: 84.87% + + +class Solution { + bool isPalindrome(String s) { + bool palindrome = true; + s = s.replaceAll(RegExp(r'[^\w\s _]+'), ''); + s = s.replaceAll(' ' , ''); + s = s.replaceAll('_' , ''); + s = s.toLowerCase(); + + for(int i = 0 ; i < s.length / 2; i++){ + + if(s[i] != s[s.length-1 - i]){ + palindrome = false; + break; + } + } + return palindrome; + } +}