Leetcode 题解
文章平均质量分 72
Britesun
这个作者很懒,什么都没留下…
展开
-
[Leetcode]First Missing Positive 首个缺失的正数
题目Given an unsorted integer array, find the smallest missing positive integer.Example 1:Input: [1,2,0] Output: 3Example 2:Input: [3,4,-1,1] Output: 2Example 3:Input: [7,8,9,11,12] Outp...原创 2018-08-09 09:16:34 · 173 阅读 · 0 评论 -
[LeetCode] Shopping Offers 购物优惠
题目In LeetCode Store, there are some kinds of items to sell. Each item has a price.However, there are some special offers, and a special offer consists of one or more different kinds of items with ...原创 2018-08-29 14:56:18 · 530 阅读 · 0 评论 -
[LeetCode] Minimum ASCII Delete Sum for Two Strings 两个字符串的最小ASCII删除和
题目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: 231 Explanation: Deleting “s” from “sea” a...原创 2018-08-25 11:31:40 · 114 阅读 · 0 评论 -
[LeetCode] Longest Palindromic Subsequence 最长回文子序列
题目Given a string s, find the longest palindromic subsequence’s length in s. You may assume that the maximum length of s is 1000.Example 1: Input: “bbbab” Output: 4 One possible longest palin...原创 2018-09-04 14:04:24 · 101 阅读 · 1 评论 -
[LeetCode] Predict the Winner 预测赢家
题目Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player pic...原创 2018-08-30 11:18:35 · 294 阅读 · 0 评论 -
[LeetCode] Target Sum 目标和
题目You are given a list of non-negative integers, a1, a2, …, an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol. Find out ho...原创 2018-09-02 14:23:26 · 379 阅读 · 0 评论 -
[LeetCode] 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 = 4 The...原创 2018-09-10 10:53:38 · 235 阅读 · 0 评论 -
[LeetCode] Largest Plus Sign 最大的加型符号
题目In a 2D grid from (0, 0) to (N-1, N-1), every cell contains a 1, except those cells in the given list mines which are 0. What is the largest axis-aligned plus sign of 1s contained in the grid? Re...原创 2018-09-13 14:39:51 · 183 阅读 · 0 评论 -
[LeetCode] 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, the原创 2018-09-11 09:44:13 · 111 阅读 · 0 评论 -
[Leetcode Longest Palindromic Substring 最长回文子串
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 ...原创 2018-08-24 15:06:13 · 117 阅读 · 0 评论 -
[LeetCode] Task Scheduler 任务行程表
题目Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task cou...原创 2018-08-21 11:42:24 · 238 阅读 · 2 评论 -
[Leetcode]Subarray Sum Equals K 子数组和为K
题目Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1:Input:nums = [1,1,1], k = 2 Output: 2Note:The le...原创 2018-08-21 10:33:12 · 458 阅读 · 0 评论 -
[leetcode] Find the duplicate number 寻找重复数
题目Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate element must exist. Assume that there is only one duplicate numbe...原创 2018-08-05 12:04:28 · 313 阅读 · 0 评论 -
[LeetCode] Valid Triangle Number 合法的三角形个数 (Java)
题目Given an array consists of non-negative integers, your task is to count the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.Exampl...原创 2018-08-06 14:53:04 · 686 阅读 · 0 评论 -
[LeetCode] Number of Subarrays with Bounded Maximum 有界限最大值的子数组数量
题目We are given an array A of positive integers, and two positive integers L and R (L <= R).Return the number of (contiguous, non-empty) subarrays such that the value of the maximum array elemen...原创 2018-08-07 10:30:35 · 152 阅读 · 0 评论 -
[Leetcode]Two sum(两数之和)系列总结
Two sum题目Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may no...原创 2018-08-08 14:56:34 · 15080 阅读 · 2 评论 -
[LeetCode] Largest Rectangle in Histogram 直方图中最大的矩形
题目 Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. A...原创 2018-08-22 11:00:51 · 142 阅读 · 0 评论 -
[LeetCode] Maximum Length of Pair Chain 链对的最大长度[DP解法]
题目You are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow another pair (a, b) if and only if b < c. Ch...原创 2018-08-26 10:15:19 · 221 阅读 · 0 评论 -
[LeetCode] 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, r...原创 2018-08-27 09:51:48 · 135 阅读 · 0 评论 -
[LeetCode] Sort Colors 颜色排序
题目Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integer...原创 2018-08-23 10:29:51 · 113 阅读 · 0 评论 -
[LeetCode] Spiral Matrix II 螺旋矩阵之二
题目Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[[ 1, 2, 3 ],[ 8, 9, 4 ],[...原创 2018-09-21 09:48:02 · 131 阅读 · 0 评论