Leetcode
crystal_zyp
未完待续......
展开
-
Minimum Depth of Binary Tree
问题描述: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.思路分析:这属于深度优先搜索的题目,但涉及到二叉树我们自然而原创 2017-09-23 19:26:53 · 200 阅读 · 0 评论 -
Different Ways to Add Parentheses
题目描述 Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.原创 2017-11-13 10:13:28 · 232 阅读 · 0 评论 -
Home Robber II
题目描述 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, all houses at this place are arranged i原创 2017-11-03 14:09:23 · 179 阅读 · 0 评论 -
Best Time to Buy and Sell Stock
Best Time to Buy and Sell Stock II1. 题目描述 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 com原创 2017-12-09 17:45:55 · 192 阅读 · 0 评论 -
Remove Boxes
题目描述 Given several boxes with different colors represented by different positive numbers. You may experience several rounds to remove boxes until there is no box left. Each time you can choose so原创 2017-12-03 13:21:16 · 294 阅读 · 0 评论 -
Minimum ASCII Delete Sum for Two Strings
题目描述思路分析这道题类似动态规划问题中的编辑距离一类,定义二维数组cost[i][j]表示当字符串s1的前i位和字符串s2的前j位字符都相同时,所删除的字符的ASCII最小值; 1)当i==0且j==0时,显然cost[i][j]==0; 2)当i==0且j!=0时,需要删除字符串s1的所有字符,同理当j==0且i!=0时,需要删除字符串s2的所有字符; 3)一般的,假设字符串s1的前(i-原创 2017-12-03 13:48:11 · 234 阅读 · 0 评论 -
Find Bottom Left Tree Value
题目描述 思路分析由于题目是要输出最后一行的最左值,可以选择二叉树的层次遍历方法: 定义一个队列nodes存放节点(先把根节点root压入队列中); 循环队列的元素直至队列为空:依次弹出队列的每一个节点node,并将该节点的左节点node->left和右节点node->right按序压入队列中,如果该节点是当前队列的第一个节点,则将value置为node->val。 一旦队列为空,val原创 2017-12-14 11:43:06 · 183 阅读 · 0 评论 -
Employee Importance
题目描述You are given a data structure of employee information, which includes the employee’s unique id, his importance value and his direct subordinates’ id.For example, employee 1 is the leader of employ原创 2017-12-14 12:50:52 · 200 阅读 · 0 评论 -
Arithmetic Slices
题目描述思路分析题目要输出A中长度至少为3的等差数列的个数,可以用动态规划的思想解决:假设dp[i]表示A中前i个元素包含的等差数列的个数,则当满足A[i]-A[i-1] == A[i-1]-A[i-2]时(等差数列的基本定义),可知dp[i]=dp[i-1]+1,输出的总个数是所有dp[i]的总和。代码实现class Solution {public: int numberOfArith原创 2017-12-22 23:26:16 · 171 阅读 · 0 评论 -
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原创 2017-10-15 16:31:52 · 279 阅读 · 0 评论 -
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原创 2017-10-15 16:03:41 · 245 阅读 · 0 评论 -
Kth Largest Element in an Array
Question: Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example: Given [3,2,1,5,6,4] and k = 2,原创 2017-09-23 19:58:21 · 184 阅读 · 0 评论 -
Two Sum
Question: 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 not原创 2017-09-12 16:33:34 · 218 阅读 · 0 评论 -
Majority Element
问题描述: Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority ele原创 2017-09-12 17:31:42 · 181 阅读 · 0 评论 -
Maximum Binary Tree
问题描述: Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: 1. The root is the maximum number in the array. 2. The left subtree is the maximum原创 2017-10-01 21:11:28 · 220 阅读 · 0 评论 -
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原创 2017-10-03 11:43:39 · 175 阅读 · 0 评论 -
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原创 2017-10-30 13:00:08 · 191 阅读 · 0 评论 -
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 c原创 2017-10-22 11:39:46 · 339 阅读 · 0 评论 -
Queue Reconstruction by Height
题目描述 Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of原创 2017-10-22 12:16:26 · 208 阅读 · 0 评论 -
Unique Paths && Unique Paths II
1. Unique Paths题目描述思路分析 整个网络矩阵没有设置障碍物:先将矩阵第一行和第一列的每个位置path[i][j]=1;从第二行第二列的格子开始,根据杨辉三角的公式可知: path[i][j]=path[i-1][j]+path[i][j-1]; 因此,从网络左上角到右下角的路径数量为path[m-1][n-1]。代码实现class Soluti原创 2018-01-20 12:12:43 · 219 阅读 · 0 评论