## Leetcode 19 Remove Nth Node From End of List Java Solution

Given a linked list, remove the n-th node from the end of list and return its head. Example: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. Solution 1: public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { if(head == null) return…… Continue reading Leetcode 19 Remove Nth Node From End of List Java Solution

Published

## Leetcode 15 3 Sum

Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: The solution set must not contain duplicate triplets. Example: Given array nums = [-1, 0, 1, 2, -1, -4], A solution set is: [ [-1, 0, 1], [-1, -1, 2] ] Solution 1:…… Continue reading Leetcode 15 3 Sum

Published

## Leetcode 5 Longest Palindromic Substring Java Solution

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Input: “babad” Output: “bab” Note: “aba” is also a valid answer. Example 2: Input: “cbbd” Output: “bb” Solution 1: class Solution { public String longestPalindrome(String s) { if(s==null || s.length()<=1) return s; boolean dp[][] =…… Continue reading Leetcode 5 Longest Palindromic Substring Java Solution

Published

## Leetcode 3 Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. Example 1: Input: “abcabcbb” Output: 3 Explanation: The answer is “abc”, with the length of 3. Example 2: Input: “bbbbb” Output: 1 Explanation: The answer is “b”, with the length of 1. Example 3: Input: “pwwkew” Output: 3 Explanation: The answer is “wke”, with…… Continue reading Leetcode 3 Longest Substring Without Repeating Characters

Published

## Leetcode 1 Two Sum Java Solution

Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9,…… Continue reading Leetcode 1 Two Sum Java Solution