Question:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.(给定一个字符串S,在S中找到最长的回文子字符串,假定最长的回文字符串长度是1000,并且在这个字符串中存在唯一的一个最长回文子字符串
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 2 3 解题: 单纯的看做一个数列题:1, 2, 5, 14, 42, 132, ... , 求通项.
336-Palindrome Pairs Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome. Example 1: Given words = ["bat", "tab"
Pow(x, n) Implement pow(x, n). 解题 直接顺序求解,时间复杂度O(N) public class Solution { /** * @param x the base number * @param n the power number * @return the result */ public double myPow(double x, int n) { // Write your code here if(x == 0) return 0; if(n ==
二分查找的基本写法: #include <vector> #include <iostream> int binarySearch(std::vector<int> coll, int key) { ; ; while (l <= r) { ; if (key == coll[m]) { return m; } if (key > coll[m]) { l = m + ; } else { r = m - ; } } ; } int main() { , ,
描述 最近在用es6解leetcode,当问题比较复杂时,有可能修正了新的错误,却影响了前面的流程.要用通用的测试工具,却又有杀鸡用牛刀的感觉,所以就写了个简单易用的leetcode开发测试工具,分享与大家. 工具安装 npm i leetcode_test 使用示例1 (问题010) codes: let test = require('leetcode_test').test /** * @param {string} s * @param {string} p * @return {boo
阅读了几个博客, 决定写一个简易版本; 忙着做更多题, 没有时间多考虑优化代码, 所以, 就写一个试试运气. http://blog.csdn.net/kenden23/article/details/17264441 http://blog.csdn.net/worldwindjp/article/details/21612731 Two versions are compared in the following blog: http://simpleandstupid.com/2014/1
题目链接:Sudoku Solver | LeetCode OJ Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character '.'. You may assume that there will be only one unique solution. A sudoku puzzle... ...and its solution n
Find the contiguous subarray within an array (containing at least one number) which has the largest product. For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the largest product = 6. 这个求最大子数组乘积问题是由最大子数组之和问题演变而来,但是却比求最大子数组之和要复
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: ["2", "1", "+", "3", "*"] -&g
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1]. Note:Could you optimize your algorithm to use only O(k) extra space? 杨辉三角想必大家并不陌生,应该最早出现在初高中的数学中,其实就是二项式系数的一种写法. 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1
Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1]. 这道题是之前那道Permutations 全排列的延伸,由于输入数组有可能出现重复数字,如果按照之前的算法运算,会有