算法课
文章平均质量分 56
huanghaodong1997
这个作者很懒,什么都没留下…
展开
-
[leetcode 42. Trapping Rain Water] Hard | Week 1
Trapping Rain Water一、题目Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,原创 2017-02-22 19:40:44 · 170 阅读 · 0 评论 -
[leetcode 104. Maximum Depth of Binary Tree]week 5
一、题目 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from theroot node down to the farthest leaf node. 二、代码 class Solution { pub原创 2017-07-07 01:56:33 · 149 阅读 · 0 评论 -
[leetcode 55. Jump Game]week 7
一、题目 Given anarray of non-negative integers, you are initially positioned at the first indexof the array. Each element in the array represents your maximum jumplength at that position. Determine原创 2017-07-07 01:58:41 · 186 阅读 · 0 评论 -
[leetcode 50. Pow(x, n)]week 11
一、题目 Implement pow(x, n). 二、代码 class Solution { public: double myPow(double x, int n) { if (n double tmp=myPower(x,-n); return 1.0/tmp; } el原创 2017-07-07 01:59:41 · 158 阅读 · 0 评论 -
[leetcode 19 Remove Nth Node From End of List]week 13
一、题目 Given a linked list, remove the nth nodefrom the end of list and return its head. For example, Given linked list: 1->2->3->4->5,and n = 2. After removing the second node from the end,原创 2017-07-07 02:01:14 · 163 阅读 · 0 评论 -
[leetcode Merge Two Sorted Lists]week 15
一、题目 Merge two sorted linked lists and return itas a new list. The new list should be made by splicing together the nodes ofthe first two lists. 二、代码 class Solution { public: ListNode* m原创 2017-07-07 02:02:29 · 148 阅读 · 0 评论 -
[leetcode Search Insert Position]week 17
一、题目 Given a sorted array and a target value,return the index if the target is found. If not, return the index where itwould be if it were inserted in order.You may assume no duplicates in the arra原创 2017-07-07 02:03:16 · 173 阅读 · 0 评论 -
[leetcode Best Time to Buy and Sell Stock]week 18
一、题目 Say you have an array for which the ith elementis the price of a given stock on day i.If you were onlypermitted to complete at most one transaction (ie, buy one and sell one shareof the stock)原创 2017-07-07 02:05:47 · 190 阅读 · 0 评论 -
[leetcode Maximum Subarray]week 19
一、题目 Findthe contiguous subarray within an array (containing at least one number) whichhas the largest sum. For example, given the array [-2, 1, -3, 4, -1, 2, 1,-5, 4], the contiguous subarray [4, -1原创 2017-07-07 02:11:39 · 206 阅读 · 0 评论 -
[leetcode 204. Count Primes]week 3
一、题目 Description: Count the number of prime numbers less than a non-negative number, n. 二、代码 class Solution { public: int countPrimes(int n) { int count=0; if (n原创 2017-07-07 01:55:27 · 143 阅读 · 0 评论 -
[lleetcode 121. Best Time to Buy and Sell Stock]|week 16
Best Time to Buy and Sell Stock 一、题目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原创 2017-06-10 12:13:53 · 209 阅读 · 0 评论 -
[leetcode 312. Burst Ballons] hard |week 2
Burst Ballons一、题目Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you原创 2017-03-05 00:28:41 · 331 阅读 · 0 评论 -
[leetcode 169. Majority Element]easy |week4
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 element always原创 2017-03-19 11:20:32 · 213 阅读 · 0 评论 -
[leetcode 513. Find Bottom Left Tree Value]medium | week6
一、题目Given a binary tree, find the leftmost value in the last row of the tree.Example 1: Input:2 / \ 1 3Output: 1 Example 2: Input: 1 / \ 2 3 / / \ 4 5 6 / 7 Output: 7二、原创 2017-03-31 10:59:32 · 294 阅读 · 0 评论 -
[leetcode 435. Non-overlapping Intervals] medium|week 8
一、题目Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.Note: You may assume the interval’s end point is always b原创 2017-04-14 16:08:23 · 266 阅读 · 0 评论 -
[leetcode 377. Combination Sum IV]medium|week10
一、题目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 possibl原创 2017-04-30 12:11:33 · 172 阅读 · 0 评论 -
[leetcode 392. Is Subsequence]medium|week 9
一、题目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原创 2017-04-21 09:16:04 · 185 阅读 · 0 评论 -
[leetcode 413. Arithmetic Slices]medium|week 12
一、题目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原创 2017-05-13 21:06:01 · 239 阅读 · 0 评论 -
[leetcode contest 582. Kill Process]week 14
一、题目Given n processes, each process has a unique PID (process id) and its PPID (parent process id).Each process only has one parent process, but may have one or more children processes. This is just li原创 2017-05-26 09:21:51 · 339 阅读 · 0 评论 -
[算法概论 8.12 k-生成树问题]
一、题目 输入:无向图G:=(V,E) 输出:G的一个生成树,其中所有节点度数都不超过K-如果该树存在 题目a:k-生成树问题是一个搜索问题。 题目b:k-生成树问题是NP-完全的。(提示:由k=2开始,考虑与Rudrata路径问题的关联) 二、证明 a.给出一个G的待确定生成树,想要判断该生成树是否为满足要求的k-生成树,只需要遍历每个节点去原创 2017-07-07 02:31:52 · 481 阅读 · 0 评论