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

Leetcode 4 Median of Two Sorted Arrays Java Solution

There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). You may assume nums1 and nums2 cannot be both empty. Example 1: nums1 = [1, 3] nums2 = [2] The median is 2.0 Example 2: nums1 = [1, 2] nums2 = [3,…… Continue reading Leetcode 4 Median of Two Sorted Arrays Java Solution