Skip to content

Commit

Permalink
W1:Q4: ValidPalindrome
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek Surve committed Aug 3, 2020
1 parent f97f684 commit 6ceb21f
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ Q. [Detect Capital](https://leetcode.com/explore/challenge/card/august-leetcodin

Q. [Design HashSet](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/549/week-1-august-1st-august-7th/3410/) ➡️ [Solution](https://github.com/abhisheksurve45/leetcode-aug-2020/blob/master/WEEK1/DesignHashSet.java)

Q. [Valid Palindrome](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/549/week-1-august-1st-august-7th/3411/) ➡️ [Solution](https://github.com/abhisheksurve45/leetcode-aug-2020/blob/master/WEEK1/ValidPalindrome.java)


## WEEK 2 🚧

26 changes: 26 additions & 0 deletions WEEK1/ValidPalindrome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class ValidPalindrome {

class Solution {
public boolean isPalindrome(String s) {
if (s == null || s.isEmpty() || s.trim().isEmpty()) return true;

int start = 0, end = s.length() - 1;

while (start <= end) {

while (start <= end && !Character.isLetterOrDigit(s.charAt(start))) start++;

while (start <= end && !Character.isLetterOrDigit(s.charAt(end))) end--;

if (start <= end && (Character.toLowerCase(s.charAt(start)) != Character.toLowerCase(s.charAt(end))))
return false;

start++;
end--;

}

return true;
}
}
}

0 comments on commit 6ceb21f

Please sign in to comment.