
leetcode
bwcxljsm
这个作者很懒,什么都没留下…
展开
-
1209. Remove All Adjacent Duplicates in String II
1209. Remove All Adjacent Duplicates in String IIGiven a string s, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them causing the left and the right side of the deleted substring to concatenate together.We re原创 2020-09-09 20:16:32 · 203 阅读 · 0 评论 -
461. Hamming Distanceq
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.Note:0 ≤ x, y < 231.Exa...原创 2018-03-23 23:43:45 · 134 阅读 · 0 评论 -
338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5 you sho...原创 2018-03-24 14:44:25 · 139 阅读 · 0 评论 -
322. 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 ...原创 2018-03-20 16:47:08 · 139 阅读 · 0 评论 -
97. Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", return false.题意:给出字...原创 2018-03-14 16:35:55 · 123 阅读 · 1 评论 -
343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, return ...原创 2018-03-25 09:42:08 · 134 阅读 · 0 评论 -
377. Combination Sum IV
Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]target = 4The possible ...原创 2018-03-21 10:58:39 · 146 阅读 · 0 评论 -
712. Minimum ASCII Delete Sum for Two Strings
Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal.Example 1:Input: s1 = "sea", s2 = "eat"Output: 231Explanation: Deleting "s" from "sea" adds the AS...原创 2018-04-08 10:23:52 · 135 阅读 · 0 评论 -
221. Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0Return...原创 2018-03-26 10:28:24 · 123 阅读 · 0 评论 -
120. Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7],...原创 2018-03-13 21:03:36 · 117 阅读 · 0 评论 -
309. Best Time to Buy and Sell Stock with Cooldown
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one an...原创 2018-03-19 15:02:28 · 165 阅读 · 0 评论 -
115. Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of S which equals T.A subsequence of a string is a new string which is formed from the original string by deleting some (can ...原创 2018-03-22 21:13:07 · 124 阅读 · 0 评论 -
64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at any...原创 2018-03-04 22:48:57 · 141 阅读 · 0 评论 -
96. Unique Binary Search Trees
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 \ / ...原创 2018-03-12 10:37:00 · 124 阅读 · 0 评论 -
62. Unique Paths
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 bott...原创 2018-03-05 13:00:29 · 169 阅读 · 0 评论 -
213. House Robber II
Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, al...原创 2018-03-18 20:20:30 · 131 阅读 · 0 评论 -
91. Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total n...原创 2018-03-12 20:04:20 · 157 阅读 · 0 评论 -
69. Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.x is guaranteed to be a non-negative integer.Example 1:Input: 4Output: 2Example 2:Input: 8Output: 2Explanation: The square root of...原创 2018-03-12 20:56:22 · 131 阅读 · 0 评论 -
63. Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the grid.For e...原创 2018-03-05 21:33:23 · 144 阅读 · 0 评论 -
70. Climbing Stairs
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?Note: Given n will be a positive int...原创 2018-03-05 22:50:23 · 123 阅读 · 0 评论 -
119. Pascal's Triangle II
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?题意:打印杨辉三角的第k行,要求空间复杂度为O(k)。思...原创 2018-03-04 21:26:45 · 117 阅读 · 0 评论 -
801. Minimum Swaps To Make Sequences Increasing
We have two integer sequences A and B of the same non-zero length.We are allowed to swap elements A[i] and B[i]. Note that both elements are in the same index position in their respective sequences.A...原创 2018-03-31 21:52:08 · 151 阅读 · 0 评论 -
790. Domino and Tromino Tiling
We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may be rotated.XX <- dominoXX <- "L" trominoXGiven N, how many ways are there to tile a 2 x N board? ...原创 2018-04-02 17:07:41 · 322 阅读 · 0 评论 -
740. Delete and Earn
Given an array nums of integers, you can perform operations on the array.In each operation, you pick any nums[i] and delete it to earn nums[i] points. After, you must delete every element equal to num...原创 2018-04-04 23:03:13 · 140 阅读 · 0 评论 -
59. Spiral Matrix II
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.Example:Input: 3Output:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]]题意:蛇形填数。思路:因为是从左上角顺时针开始填,所以...原创 2018-04-17 21:10:39 · 164 阅读 · 0 评论 -
66. Plus One
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each element i...原创 2018-04-19 11:39:34 · 155 阅读 · 0 评论 -
54. Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.Example 1:Input:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,4,5]Exampl...原创 2018-04-21 13:48:30 · 146 阅读 · 0 评论 -
374. Guess Number Higher or Lower
We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number is higher or low...原创 2018-05-09 18:42:17 · 140 阅读 · 0 评论 -
268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.Example 1Input: [3,0,1]Output: 2Example 2Input: [9,6,4,2,3,5,7,0,1]Output: 8Not...原创 2018-05-05 11:54:05 · 125 阅读 · 0 评论 -
897——Increasing Order SearchTree
题目Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only 1 right child.大意给出一个树,重新排列,使得最左的节点是树的根...原创 2018-12-19 20:40:59 · 227 阅读 · 0 评论 -
543Diameter of Binary Tree
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may n...原创 2019-01-19 14:50:09 · 214 阅读 · 0 评论 -
263. Ugly Number
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it i...原创 2018-03-29 11:07:37 · 132 阅读 · 0 评论 -
264. Ugly Number II
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugl...原创 2018-03-29 11:03:58 · 118 阅读 · 0 评论 -
673. Number of Longest Increasing Subsequence
Given an unsorted array of integers, find the number of longest increasing subsequence.Example 1:Input: [1,3,5,4,7]Output: 2Explanation: The two longest increasing subsequence are [1, 3, 4, 7] and [...原创 2018-04-02 20:02:36 · 133 阅读 · 0 评论 -
132. Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Return 1 since t...原创 2018-03-27 21:21:54 · 118 阅读 · 0 评论 -
650. 2 Keys Keyboard
Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step:Copy All: You can copy all the characters present on the notepad (partial copy is...原创 2018-04-10 16:45:20 · 162 阅读 · 0 评论 -
647. Palindromic Substrings
Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist of...原创 2018-04-11 09:36:23 · 202 阅读 · 0 评论 -
300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], therefore th...原创 2018-04-03 20:28:16 · 160 阅读 · 0 评论 -
667. Beautiful Arrangement II
Given two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list is [a1, a2, a3, ... , a...原创 2018-03-28 19:22:25 · 133 阅读 · 0 评论 -
368. Largest Divisible Subset
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj= 0 or Sj % Si = 0.If there are multiple solutions, return...原创 2018-03-28 19:33:06 · 125 阅读 · 0 评论