Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NirmalSilwal/Data-Structure-and-Algorithm-Java-interview-kit
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: ifenil/Data-Structure-and-Algorithm-Java-interview-kit
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Oct 3, 2020

  1. Valid_Palindrome

    ifenil committed Oct 3, 2020
    Copy the full SHA
    68948a2 View commit details
  2. Valid_Palindrome

    ifenil committed Oct 3, 2020
    Copy the full SHA
    e25659f View commit details
Showing with 47 additions and 0 deletions.
  1. +47 βˆ’0 Leetcode/Leetcode_August_Challenge/Valid_Palindrome.java
47 changes: 47 additions & 0 deletions Leetcode/Leetcode_August_Challenge/Valid_Palindrome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package Leetcode_August_Challenge;

public class Valid_Palindrome {

public boolean isPalindrome(String s) {
// check string if it's null no need to go further direct return false

if(s==null){
return false;
}

// if string contain some char as uppercase or lowercase
// this will convert whole string to lowercase
s = s.toLowerCase();

// pointed i to intially at 0
// and j to end of the string (last character)
int i=0;
int j=s.length()-1;


while(i<j){
//if i<j and string char contain a-z and 0-9 loop -> true

while(i<j && !((s.charAt(i)>='a' && s.charAt(i)<='z')
|| (s.charAt(i)>='0'&&s.charAt(i)<='9'))){
i++;
}

while(i<j && !((s.charAt(j)>='a' && s.charAt(j)<='z')
|| (s.charAt(j)>='0'&&s.charAt(j)<='9'))){
j--;
}
// if one of string char not match i to j
// it will return false
if(s.charAt(i) != s.charAt(j)){
return false;
}

i++;
j--;
}
// else return true
return true;

}
}