`
文章列表
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below). How many possible unique path ...
Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.   public class Solution { // keep track of min ...
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, givens = "catsanddog",dict = ["cat", "cats", "and", "sand", " ...
[题目] You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? [分析] 一维动态规划入门题   public class Solution { // O(n)空间 public int climbStairs0(int n) { if (n <= 0) ...
[题目] 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.   [分析] n个节点的BST的结构数等于从1到n依次为root节点对应的BST个数,记录中间结果避免重复计算。   public class Solution { // Method 2 //dp[i] : number of unique BST ...
[题目] 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. [分析] 注意到负负得正,所以求解过程中需要分别计算保留以当前数组元素A[i]结尾的连续子数组乘积的最大值和最小值   public class Solution ...
[题目] Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, givens = "leetcode",dict = ["leet", "code"]. Return true because "leetcode" can be segmented ...
[题目] You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent ...
Given a sorted integer array where the range of elements are [0, 99] inclusive, return its missing ranges.For example, given [0, 1, 3, 50, 75], return [“2”, “4->49”, “51->74”, “76->99”] [TIPS] 1.特殊情况向面试官确认,数组为空或者包含全部元素返回什么 2. 注意可扩展性,题意为[0,99],扩展为[start, end]3 findMissingRanges2方法未在online ...
Global site tag (gtag.js) - Google Analytics