LeetCode – Valid Palindrome (Java)

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, “Red rum, sir, is murder” is a palindrome, while “Programcreek is awesome” is not. Note: Have you consider that the string might be empty? This is a good question to ask during an interview. For the purpose … Read more

LeetCode – Longest Consecutive Sequence (Java)

Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, given [100, 4, 200, 1, 3, 2], the longest consecutive elements sequence should be [1, 2, 3, 4]. Its length is 4. Your algorithm should run in O(n) complexity. Java Solution 1 Because it requires O(n) complexity, we … Read more

LeetCode – Remove Duplicates from Sorted List

Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. Thoughts The key of this problem is using the right loop condition. And change what is necessary in each loop. You can use different iteration conditions like the following 2 … Read more