Given a , and there exists one unique longest palindromic substring. https://leetcode.com/problems/longest-palindromic-substring/ 求最大回文的长度,其实这道题比上一道有意思. 方法1 循环查询 (该方案为O(N*N*N)) public static boolean isPalindrome(String s, int start, int end) { if (((…
https://leetcode.com/problems/median-of-two-sorted-arrays/ 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)). Example 1: nums1 =…
Given a string, find the length of the longest substring without repeating characters. Examples: Given . Given . Given . Note that the answer must be a substring, "pwke" is a subsequence and not a substring. 寻找最长的不重复串,略像滑动窗口. char[] buff; //used…
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6 ->…
Implement regular expression matching with support for '.' and '*'. 首先这里有个可能大家不知道的地方: if p[0] = '*', the string must be an invalid string.that is what Regular Expression defined. 这是别人在评论的时候说的.也就是说,pattern的第一个不可以是*: class Solution { public: bool isMat…
1 题目描述 Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element always exist in the array. 2 分析 求主元素有两种O(n)量级的算法…