Posts

Showing posts from March, 2023

strings (DSA)

1. PALINDROME PROBLEM OF STRING Solution Convert the string to lowercase. Remove all the special characters and spaces from the string. Initialize two pointers, one at the beginning and one at the end of the string. Compare the characters pointed by the two pointers. If they are equal, move the left pointer to the right and the right pointer to the left. If they are not equal, return 0. Repeat step 4 until the two pointers cross each other. If the two pointers cross each other, the string is a palindrome, and we can return 1 code:        public class Solution { public int isPalindrome ( String A ) { // Convert the string to lowercase A = A . toLowerCase (); // Remove all the special characters and spaces from the string A = A . replaceAll ( "[^a-zA-Z0-9]" , "" ); // Initialize two pointers int left = 0 ; int right = A . length () - 1 ; // Compare the characters pointed by the two pointers while ( left...