
leetCode
名字被猪吃掉了
这个作者很懒,什么都没留下…
展开
-
牛客 -- leetcode -- max-points-on-a-line
题目描述Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.我的想法:1、算法设计很简单的题目,但是真正用数据结构实现起来却不容易的一道题。2、刚开始考虑分三类进行解决,一类横坐标相同,一类纵坐标相同的点,一类斜率点3、考...原创 2019-07-29 21:01:55 · 132 阅读 · 0 评论 -
leetcode -- 638. 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 a sa...转载 2019-07-05 17:31:13 · 187 阅读 · 0 评论 -
leetcode -- 841. Keys and Rooms
There are N rooms and you start in room 0.Each room has a distinct number in 0, 1, 2, ..., N-1, and each room may havesome keys to access the next room.Formally, each room ihas a list of keys r...原创 2019-07-05 16:11:30 · 124 阅读 · 0 评论 -
leetcode -- 515. Find Largest Value in Each Tree Row
You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 3 9Output: [1, 3, 9]来源:力扣(LeetCode)链接:http...原创 2019-07-05 14:47:36 · 119 阅读 · 0 评论 -
leetcode -- 877. Stone Game
Alex and Lee play a game with piles of stones.There are an even number ofpiles arranged in a row, and each pile has a positive integer number of stones piles[i].The objective of the game is to en...转载 2019-06-30 11:05:41 · 158 阅读 · 0 评论 -
leetcode -- Unique Binary Search Trees II
Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ...n.Example:Input: 3Output:[[1,null,3,2],[3,2,null,1],[3,1,null,null,2],[2,1,3]...转载 2019-06-30 10:05:37 · 107 阅读 · 0 评论 -
leetcode -- 746. Min Cost Climbing Stairs
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of ...原创 2019-06-30 09:24:49 · 122 阅读 · 0 评论 -
leetcode -- 413. Arithmetic Slices
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequence:...原创 2019-07-04 20:18:20 · 161 阅读 · 0 评论 -
leetcode -- Minimum Failing Path Sum
Given a square array of integers A, we want the minimum sum of a falling path through A.A falling path starts at any element in the first row, and chooses one element from each row.The next row's ...原创 2019-07-04 19:07:23 · 150 阅读 · 0 评论 -
leetcode -- 279. Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.Example 1:Input: n = 12Output: 3Explanation: 12 = 4 + 4 + 4.Example 2...转载 2019-06-29 10:55:49 · 106 阅读 · 0 评论 -
leetcode -- 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 a non-empty string containing only digits, determine the ...转载 2019-06-29 09:39:14 · 126 阅读 · 0 评论 -
leetcode -- 304. Range Sum Query 2D - Immutable
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).The above rectangle (with the red borde...转载 2019-06-29 08:54:38 · 134 阅读 · 0 评论 -
leetcode -- 300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4Explanation: The longest increasing subsequence is [2,3,7,101...原创 2019-06-28 21:38:52 · 119 阅读 · 0 评论 -
leetcode -- 96. Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1 ...n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a total of 5 unique BST's: 1 ...转载 2019-06-28 21:22:37 · 152 阅读 · 0 评论 -
leetcode -- 63. 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 a...原创 2019-06-28 20:50:18 · 183 阅读 · 0 评论 -
leetcode -- 714. Best Time to Buy and Sell Stock with Transaction Fee
Your are given an array of integers prices, for which the i-th element is the price of a given stock on day i; and a non-negative integer fee representing a transaction fee.You may complete as many ...转载 2019-07-05 18:58:09 · 130 阅读 · 0 评论 -
leetcode -- 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.Example 1:Input: 2Output: 1...转载 2019-07-05 19:30:03 · 115 阅读 · 0 评论 -
leetcode -- 890. Find and Replace Pattern
You have a list ofwords and a pattern, and you want to know which words in words matches the pattern.A word matches the pattern if there exists a permutation of letters p so that after replacing ev...原创 2019-07-05 20:31:31 · 170 阅读 · 0 评论 -
leetcode -- 1105. Filling Bookcase Shelves
We have a sequence of books: the i-th book has thickness books[i][0] and height books[i][1].We want to place these books in order onto bookcase shelves that have total width shelf_width.We choose ...转载 2019-07-24 14:56:04 · 162 阅读 · 0 评论 -
牛客 -- leetcode -- evaluate-reverse-polish-notation
题目描述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", "+...原创 2019-07-29 11:35:52 · 120 阅读 · 0 评论 -
leetcode -- 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 ...原创 2019-07-24 09:50:50 · 127 阅读 · 0 评论 -
leetcode -- 392. Is Subsequence
Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string,...原创 2019-07-07 15:19:52 · 112 阅读 · 0 评论 -
leetcode -- 139. Word Break
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.Note:The ...转载 2019-07-07 11:02:59 · 140 阅读 · 0 评论 -
leetcode -- 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 n...转载 2019-07-07 10:32:12 · 212 阅读 · 0 评论 -
leetcode -- 547. Friend Circles
There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then ...原创 2019-07-07 09:57:51 · 168 阅读 · 0 评论 -
leetcode -- 947. Most Stones Removed with Same Row or Column
On a 2D plane, we place stones at some integer coordinate points.Each coordinate point may have at most one stone.Now, a move consists of removing a stonethat shares a column or row with another ...转载 2019-07-07 09:15:04 · 197 阅读 · 0 评论 -
leetcode -- 494. Target Sum
Input: nums is [1, 1, 1, 1, 1], S is 3.Output: 5Explanation:-1+1+1+1+1 = 3+1-1+1+1+1 = 3+1+1-1+1+1 = 3+1+1+1-1+1 = 3+1+1+1+1-1 = 3There are 5 ways to assign symbols to make the sum of nums...转载 2019-07-07 08:41:21 · 140 阅读 · 0 评论 -
leetcode -- 165. Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1;if version1 < version2 return -1;otherwise return 0.You may assume that the version strings are non-empty an...原创 2019-07-06 16:36:40 · 212 阅读 · 0 评论 -
leetcode -- 646. Maximum Length of Pair Chain
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. Chain ...转载 2019-07-06 15:14:15 · 135 阅读 · 0 评论 -
leetcode -- 983. Minimum Cost For Tickets
In a country popular for train travel, youhave planned some train travelling one year in advance.The days of the year that you will travel is given as an array days.Each day is an integer from 1 ...转载 2019-07-06 14:39:55 · 167 阅读 · 0 评论 -
leetcode -- 337. House Robber III
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour...转载 2019-07-06 10:27:46 · 274 阅读 · 0 评论 -
leetcode -- 695. Max Area of Island
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrou...原创 2019-07-06 08:37:57 · 136 阅读 · 0 评论 -
leetcode -- 1091. 二进制矩阵中的最短路径
在一个 N × N 的方形网格中,每个单元格有两种状态:空(0)或者阻塞(1)。一条从左上角到右下角、长度为 k 的畅通路径,由满足下述条件的单元格 C_1, C_2, ..., C_k 组成: 相邻单元格 C_i 和 C_{i+1} 在八个方向之一上连通(此时,C_i 和 C_{i+1} 不同且共享边或角) C_1 位于 (0, 0)(即,值为 grid[0][0])...原创 2019-07-09 16:11:52 · 308 阅读 · 0 评论 -
leetcode -- 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...转载 2019-07-03 21:29:36 · 142 阅读 · 0 评论 -
leetcode -- 129. 求根到叶子节点数字之和
给定一个二叉树,它的每个结点都存放一个0-9的数字,每条从根到叶子节点的路径都代表一个数字。例如,从根到叶子节点路径1->2->3代表数字123。计算从根到叶子节点生成的所有数字之和。说明:叶子节点是指没有子节点的节点。示例 1:输入: [1,2,3] 1 / \ 2 3输出: 25解释:从根到叶子节点路径 1->2 ...原创 2019-05-12 10:01:51 · 166 阅读 · 0 评论 -
leetcode-- 124. 二叉树中的最大路径和
给定一个非空二叉树,返回其最大路径和。本题中,路径被定义为一条从树中任意节点出发,达到任意节点的序列。该路径至少包含一个节点,且不一定经过根节点。示例 1:输入: [1,2,3] 1 / \ 2 3输出: 6示例2:输入: [-10,9,20,null,null,15,7] -10 / \ 9 20 ...原创 2019-05-12 08:42:50 · 144 阅读 · 0 评论 -
leetcode--116. 填充每个节点的下一个右侧节点指针
给定一个完美二叉树,其所有叶子节点都在同一层,每个父节点都有两个子节点。二叉树定义如下:struct Node { int val; Node *left; Node *right; Node *next;}填充它的每个 next 指针,让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点,则将 next 指针设置为NULL。初始状态下,所有next 指针都被...原创 2019-05-11 15:49:07 · 129 阅读 · 0 评论 -
leetcode--114 二叉树展开为链表
给定一个二叉树,原地将它展开为链表。例如,给定二叉树 1 / \ 2 5 / \ \3 4 6将其展开为:1 \ 2 \ 3 \ 4 \ 5 \ 6AC:/** * Definition for a binary tree...原创 2019-05-11 15:07:38 · 102 阅读 · 0 评论 -
leetcode--113.路径总和 Ⅱ
给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径。说明:叶子节点是指没有子节点的节点。示例:给定如下二叉树,以及目标和sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ ...原创 2019-05-11 14:21:30 · 202 阅读 · 0 评论 -
leetcode--70. 爬楼梯
假设你正在爬楼梯。需要n阶你才能到达楼顶。每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?注意:给定n是一个正整数。示例 1:输入: 2输出: 2解释: 有两种方法可以爬到楼顶。1. 1 阶 + 1 阶2. 2 阶示例 2:输入: 3输出: 3解释: 有三种方法可以爬到楼顶。1. 1 阶 + 1 阶 + 1 阶2. ...原创 2019-05-15 21:27:00 · 230 阅读 · 0 评论