Leetcode - Count Complete Tree Nodes
Leetcode - Remove Nth Node From End of List

Leetcode - Valid Palindrome

violet posted @ Jun 25, 2020 01:20:12 AM in 算法 with tags Algorithm Golang string , 374 阅读

https://leetcode.com/problems/valid-palindrome/

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Note: For the purpose of this problem, we define empty string as valid palindrome.

Example 1:

Input: "A man, a plan, a canal: Panama"
Output: true

Example 2:

Input: "race a car"
Output: false

 

func isPalindrome(s string) bool {
    i := 0
    j := len(s)-1
    for i < j {
        for i < j && !(isLetter(s[i]) || (s[i] >= '0' && s[i] <= '9')) {
            i++
        }
        for j > i && !(isLetter(s[j]) || (s[j] >= '0' && s[j] <= '9')) {
            j--
        }
        
        if s[i] != s[j] {
            if !isLetter(s[i]) && !isLetter(s[j]) {
                return false
            }
            if (!isLetter(s[i]) && isLetter(s[j])) || (isLetter(s[i]) && !isLetter(s[j])) {
                return false
            }
            if isLetter(s[i]) && isLetter(s[j]) && (s[i] + 32 != s[j]) && (s[i] - 32 != s[j]) {
                return false
            }
        }
        i++
        j--
    }
    return true
}

func isLetter(s byte) bool {
    return (s >= 'a' && s <= 'z') || (s >= 'A' && s <= 'Z')
}
Plus 1, Previous Pap 说:
Feb 13, 2023 02:57:13 PM

The authentic Class Plus 1, Previous Paper 2024 will definitely be posted on the official website on the day specified by the authorities. For the time being, we are giving a Download Question Paper 2024 to assist students in getting started with their studies. Plus 1, Previous Paper 2024 We'd like to emphasize that this Question Paper 2024 is just a sample that might be altered throughout the 2024 session.

voir les likes insta 说:
Jul 15, 2023 09:26:03 PM

Instagram est une plate-forme de proposition de médias sociaux très célèbre et sensationnelle où les utilisateurs peuvent lancer des photos et des vidéos avec leurs abonnés. voir les likes instagram de quelqu'un Cette application de plate-forme de proposition est présente sous forme d’application mobile pour les appareils iOS et Android ainsi que sur le navigateur de la page Web.

Punjab 7th Class Bo 说:
Aug 23, 2023 06:22:40 PM

PSEB 6th Class Book 2024 is Available here on the official web portal High School Book in pdf format are Available in Online mode. Punjab Board Class Textbook 2024 are the most Important Study Materials for the Students. Punjab High School Students can Download the E-Books and Study Materials for the Final Exam Preparation process.Here we are Providing Punjab 7th Class Books 2024 the Facility to Download Latest Edition PSEB Class Textbook 2024, Students You can Download for Hindi, English and Urdu Medium Schools.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter