`
文章列表
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. 题目的要求是给定一个字符串,找到一个最长的回文子串。 解决这道题首先我们要知道回文字符串的概念,单个字符属于回文字符串,例如"a", 还有另外的形式例如:“baab”, "bab",其中"bab&q ...
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1. ...
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 -> 4) Output: 7 -> 0 -> 8 题目的意思是给定两个单向链表, ...
Design a data structure that supports the following two operations: void addWord(word) bool search(word) search(word) can search a literal word or a regular expression string containing only letters a-z or .. A . means it can represent any one letter. For example: addWord("bad") addWord( ...
Implement a trie with insert, search, and startsWith methods. Note: You may assume that all inputs are consist of lowercase letters a-z. 题目的要求很简单,完成一个前缀树的插入,搜索等功能。 Trie为前缀树,又称字典树或单词查找树,是一种用于快速检索的多叉树结构,例如,基于英文字母的前缀树是一个26叉树(a-z),基于数字的前缀树是一个10叉树(0-9)。前缀树的核心思想是用空间换时间。利用字符串的公共前缀来降低查询时间的开销,从而可以提高效率。前缀树的 ...
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1] Given the total number of courses and a list of prerequisite pairs, return the ordering of ...
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1] Given the total number of courses and a list of prerequisite pairs, is it possible for you ...
Given a 2D matrix matrix[][], find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2). Example: Given matrix = [   [3, 0, 1, 4, 2],   [5, 6, 3, 2, 1],   [1, 2, 0, 1, 5],   [4, 1, 0, 1, 7],   [1, 0, 3, 0, 5] ] sumRegion(2, 1, ...
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. The update(i, val) function modifies nums by updating the element at index i to val. Example: Given nums = [1, 3, 5] sumRange(0, 2) -> 9 update(1, 2) sumRange(0, 2) -> 8 Note: The array is o ...
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: Given nums = [-2, 0, 3, -5, 2, -1] sumRange(0, 2) -> 1 sumRange(2, 5) -> -1 sumRange(0, 5) -> -3 Note: You may assume that the array does not change. There are many calls to sumR ...
Coin Change You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1. Note: You may assume that ...
有关异构词的题目,考察我们对字符串的处理能力,这里列举leetcode两道关于异构词的题目。 1,Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. Note: You may assume t ...
Number of Islands Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water. Example 1: 11110 11010 1 ...
有关unique 二叉搜索树的题目有两个,第一道题目是确定二叉搜索树的个数,第二道题目是输出所有的二叉搜索树,这两道题目属于比较难的题目,对于解决它们的方法也是比较重要的,我们要掌握。 1,Unique Binary Search Trees 给定 ...
有关计算一个数幂的题目考查我们对于边界问题的处理,比如如何处理负数越界问题,以及如何通过位运算提高运算速度。这里列举leetcode中有关pow()方法的两道题目。 1,Power of Two 给定一个整数,判断这个数是否是2的幕。 这道题目比较简单,我们通过位与运算就可以解决,有关位运算的知识大家可以参考位运算这篇文章。代码如下: public class Solution { public boolean isPowerOfTwo(int n) { if(n < 0) return false; return ...
Global site tag (gtag.js) - Google Analytics