Three Sum Closest - Leet Code Solution
Problem Statement Given an array nums of n integers and an integer target, find…
September 11, 2020
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
Input: "A man, a plan, a canal: Panama"
Output: true
Input: "race a car"
Output: false
Please note the special conditions:
Lets run our simple two pointer system where:
public static boolean isAlphanumeric(char c) {
return Character.isDigit(c) || Character.isLetter(c);
}
public boolean isPalindrome(String s) {
if (s.length() == 0) return true;
int l = 0;
int r = s.length()-1;
while (l < r) {
while (!isAlphanumeric(s.charAt(l)) && l < r) {
l++;
}
while (!isAlphanumeric(s.charAt(r)) && l < r) {
r--;
}
if (Character.toLowerCase(s.charAt(l)) != Character.toLowerCase(s.charAt(r))) {
return false;
}
l++;
r--;
}
return true;
}
Its O(n)
Problem Statement Given an array nums of n integers and an integer target, find…
Its a tree based data structure which is a complete binary tree(all nodes have…
This problem is a simple mathematical calculation. Lets start deriving some…
This algorithm is very useful for large input. And, is quite efficient one. It…
Min Priority Queue is a data structure which manage a list of keys(values). And…
Problem Statement You are given two non-empty linked lists representing two non…
Introduction This post has the complete code to send email through smtp server…
Introduction In a normal email sending code from python, I’m getting following…
Introduction In one of my app, I was using to talk to . I have used some event…
Introduction So you have a Django project, and want to run it using docker image…
Introduction It is very important to introduce few process so that your code and…
Introduction In this post, we will see a sample Jenkin Pipeline Groovy script…