算法作业
原帅原帅
做图像处理的研究生
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
86. Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of t原创 2017-09-04 22:28:55 · 234 阅读 · 0 评论 -
算法作业_31(2017.6.14第十七周)
455. Assign CookiesAssume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is原创 2017-06-11 17:21:29 · 265 阅读 · 0 评论 -
算法作业_30(2017.6.13第十七周)
198. House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them i原创 2017-06-11 09:57:15 · 268 阅读 · 0 评论 -
NP完全问题
8.8In the EXACT 4 SAT problem, the input is a set of clauses, each of which is a disjunction of exactly four literals, and such that each variable occurs at most once in each clause. The goal is to原创 2017-07-01 11:16:30 · 354 阅读 · 0 评论 -
算法作业_29(2017.6.12第十七周)
343. Integer BreakGiven 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 exa原创 2017-06-09 14:58:08 · 274 阅读 · 0 评论 -
算法作业_28(2017.6.8第十六周)
64. Minimum Path SumGiven 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 mo原创 2017-06-08 20:56:46 · 238 阅读 · 0 评论 -
算法作业_27(2017.6.8第十六周)
120. TriangleGiven a triangle, find the minimum path sum from top to bottom. Each step you may move to adjachttp://write.blog.youkuaiyun.com/posteditent numbers on the row below.For example, given t原创 2017-06-08 18:39:53 · 269 阅读 · 0 评论 -
算法作业_26(2017.6.6第十六周)
583. Delete Operation for Two StringsGiven two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one character原创 2017-06-06 19:33:10 · 259 阅读 · 0 评论 -
算法作业_40(2017.6.22第十八周)
121. Best Time to Buy and Sell StockSay 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原创 2017-06-16 17:18:04 · 403 阅读 · 0 评论 -
算法作业_25(2017.6.1第十五周)
最长公共子序列与最长公共子串(动态规划问题)一直不明白最长公共子串和最长公共子序列的区别,上网查了下,最长公共子串(Longest Common Substirng)和最长公共子序列(Longest Common Subsequence,LCS)的区别为:子串是串的一个连续的部分,子序列则是从不改变序列的顺序,而从序列中去掉任意的元素而获得新的序列;也就是说,子串中字符的位置必须是连续的,子序原创 2017-06-05 22:03:06 · 319 阅读 · 0 评论 -
算法作业_32(2017.6.15第十七周)
392. Is SubsequenceGiven 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 lon原创 2017-06-12 16:07:04 · 244 阅读 · 0 评论 -
算法作业_41(2017.6.24第十八周)
133. Clone GraphClone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # a原创 2017-06-24 15:10:13 · 264 阅读 · 0 评论 -
算法作业_33(2017.6.16第十七周)(算法机考模拟题1)
1000. 函数求值Description定义超级和函数F如下:F(0, n) = n,对于所有的正整数n..F(k, n) = F(k – 1, 1) + F(k – 1, 2) + … + F(k – 1, n),对于所有的正整数k和n. 请实现下面Solution类中计算F(k, n)的函数(1 class Solution {public:原创 2017-06-13 20:37:22 · 591 阅读 · 0 评论 -
算法作业_39(2017.6.21第十八周)
101. Symmetric TreeGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2原创 2017-06-14 18:42:46 · 265 阅读 · 0 评论 -
算法作业_38(2017.6.20第十八周)
226. Invert Binary TreeInvert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1100. Same TreeGiven two binary trees, writ原创 2017-06-14 15:52:09 · 308 阅读 · 0 评论 -
算法作业_43(2017.6.28第十九周)
[LeetCode] Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function t原创 2017-06-27 14:58:35 · 302 阅读 · 0 评论 -
算法作业_42(2017.6.27第十九周)
207. Course ScheduleThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1原创 2017-06-27 14:41:54 · 402 阅读 · 0 评论 -
算法作业_44(2017.6.27第十九周)(算法机考模拟题4)
1004. 无环图Description 在图论中,如果一个有向图从任意顶点出发无法经过若干条边回到该点,则这个图是一个有向无环图(Directed Acyclic Graph,DAG). 对于一个n个节点的有向图(节点编号从0到n-1),请判断其是否为有向无环图. 图的节点数和边数均不多于100000. 请为下面的Solution类实现解决上述问题的isDAG原创 2017-06-27 15:53:32 · 568 阅读 · 0 评论 -
225. Implement Stack using Queues
225. Implement Stack using QueuesImplement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get t原创 2017-07-05 19:42:18 · 257 阅读 · 0 评论 -
算法作业_37(2017.6.19第十八周)
104. Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.原创 2017-06-14 15:23:41 · 260 阅读 · 0 评论 -
算法作业_36(2017.6.16第十七周)(算法机考模拟题5)
1005. 最大和从数列A[0], A[1], A[2], ..., A[N-1]中选若干个数,要求相邻的数不能都选,也就是说如果选了A[i], 就不能选A[i-1]和A[i+1]. 求能选出的最大和. 1 请为下面的Solution类实现解决上述问题的函数maxSum,函数参数A是给出的数列,返回值为所求的最大和. class Solution {p原创 2017-06-14 12:13:29 · 316 阅读 · 0 评论 -
算法作业_35(2017.6.16第十七周)(算法机考模拟题3)
1002. 等价二叉树两个二叉树结构相同,且对应结点的值相同,我们称这两个二叉树等价. 例如:以下两个二叉树等价 1 1 / \ / \ 2 3 2 3而以下两个则不等价 1 1 / \ / \原创 2017-06-13 22:24:59 · 265 阅读 · 0 评论 -
算法作业_22(2017.5.18第十三周)
232. Implement Queue using StacksImplement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.p原创 2017-05-18 19:10:19 · 269 阅读 · 0 评论 -
算法作业_21(2017.5.11第十二周)
572. Subtree of Another TreeGiven two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of原创 2017-05-16 19:39:03 · 296 阅读 · 0 评论 -
算法作业_7(2017.3.16第四周)
496. Next Greater Element IYou are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in t原创 2017-03-16 19:55:15 · 254 阅读 · 0 评论 -
算法作业_11(2017.3.29第六周)
507. Perfect NumberWe define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.Now, given an integer n, write a function that returns t原创 2017-03-29 19:22:48 · 237 阅读 · 0 评论 -
算法作业_9(2017.3.22第五周)
375. Guess Number Higher or Lower IIWe 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原创 2017-03-22 20:09:42 · 281 阅读 · 0 评论 -
算法作业_6(2017.3.11第三周)
338. Counting BitsGiven 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.Exa原创 2017-03-11 22:25:28 · 299 阅读 · 0 评论 -
算法作业_5(2017.3.7第三周)
206. Reverse Linked ListReverse a singly linked list.解析:题目要求很简单 ,反转一个单链表。一个比较简单的思路就是头插法,依次去下链表,然后插入到新链表的头结点的下一个。由于题目没有定义头结点,为了操作方便,定义两个空头结点指向链表。只需要遍历一次链表,所以时间复杂度为O(n)代码如下:/** * Definiti原创 2017-03-07 21:57:02 · 338 阅读 · 0 评论 -
算法作业_8(2017.3.19第四周)
242. Valid AnagramGiven two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.原创 2017-03-19 19:40:28 · 116 阅读 · 0 评论 -
算法作业_1(2017.2.25第一周)
328. Odd Even Linked ListGiven a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.原创 2017-02-25 19:38:36 · 431 阅读 · 0 评论 -
算法作业_4(2017.3.4第二周)
53. Maximum SubarrayFind the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous suba原创 2017-03-04 16:10:33 · 268 阅读 · 0 评论 -
算法作业_2(2017.3.2第二周)
169. Majority ElementGiven 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 th原创 2017-03-02 20:07:44 · 293 阅读 · 0 评论 -
算法作业_14(2017.4.12第八周)
70. Climbing StairsYou 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: Giv原创 2017-04-12 14:00:17 · 225 阅读 · 0 评论 -
算法作业_12(2017.4.5第七周)
503. Next Greater Element IIGiven a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number原创 2017-04-05 18:37:50 · 316 阅读 · 0 评论 -
算法作业_16(2017.4.18第九周)
522. Longest Uncommon Subsequence IIGiven a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of原创 2017-04-18 19:54:20 · 308 阅读 · 0 评论 -
算法作业_18(2017.4.26第十周)
551. Student Attendance Record IYou are given a string representing an attendance record for a student. The record only contains the following three characters:'A' : Absent.'L' : Late.'P' : Pr原创 2017-04-26 18:50:00 · 226 阅读 · 0 评论 -
算法作业_17(2017.4.24第十周)
292. Nim GameYou are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the las原创 2017-04-24 18:35:26 · 221 阅读 · 0 评论 -
算法作业_24(2017.5.23第十四周)
563. Binary Tree TiltGiven a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and原创 2017-05-24 22:00:32 · 282 阅读 · 0 评论 -
算法作业_20(2017.5.4第十一周)
552. Student Attendance Record IIGiven a positive integer n, return the number of all possible attendance records with length n, which will be regarded as rewardable. The answer may be very large,原创 2017-05-04 18:19:14 · 253 阅读 · 0 评论
分享