- 博客(21)
- 收藏
- 关注
原创 【1004】无环图
题目:在图论中,如果一个有向图从任意顶点出发无法经过若干条边回到该点,则这个图是一个有向无环图(Directed Acyclic Graph,DAG). 对于一个n个节点的有向图(节点编号从0到n-1),请判断其是否为有向无环图.图的节点数和边数均不多于100000.请为下面的Solution类实现解决上述问题的isDAG函数,函数参数中n为图的节点数,edges是边集,edg
2017-06-26 14:16:36
319
原创 【1003】相连的1
题目:对于一个01矩阵A,求其中有多少片连成一片的1. 每个1可以和上下左右的1相连.请为下面的Solution类实现解决这一问题的函数countConnectedOnes,函数参数A为给出的01矩阵,A的行数和列数均不大于1000. 函数的返回值是问题的答案.class Solution {public:int countConnectedOnes(vector>&
2017-06-26 14:13:41
257
原创 【1002】等价二叉树
题目:两个二叉树结构相同,且对应结点的值相同,我们称这两个二叉树等价.例如:以下两个二叉树等价1 1/ \ / \2 3 2 3而以下两个则不等价1 1/ \ / \2 3 3 2以下两个也不等价1 1/ \ / \2 3 2 2给出两个二叉树p和q,判断它们是否等价.p和q的结点数不多于100000,每个结点的数值在1和10
2017-06-24 00:23:01
230
原创 【1001】 会议安排
题目:N个会议要同时举行,参会人数分别为A[0], A[1], ..., A[N-1]. 现有M个会议室,会议室可容纳人数分别为B[0], B[1], ..., B[M-1]. 当A[i]1 请为下面的Solution类实现解决上述问题的函数assignConferenceRoom. 函数参数A和B的意义如上,返回值为最多可安排的会议数.class Solution {
2017-06-18 15:54:32
738
原创 【1000】函数求值
题目:定义超级和函数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:int F(int k, int n) {
2017-06-18 13:48:23
348
原创 8.14
题目:Prove that the following problem is NP-complete:given an undirected graph G=[V,E]and an integer k,return a clique of size k as well as an independent set of size k,provided both exist.解:将最大团问
2017-06-11 17:47:45
238
原创 【55】Jump Game
题目:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determ
2017-06-11 15:06:14
130
原创 【394】Decode String
题目:Given an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k
2017-06-06 23:23:52
165
原创 【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,
2017-05-28 18:52:20
240
原创 【442】Find All Duplicates in an Array
题目:Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it witho
2017-05-27 21:50:45
165
原创 【268】 Missing Number
题目:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm sh
2017-05-18 15:51:12
301
原创 【486】 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 pi
2017-05-08 01:01:04
164
原创 【516】 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:4One possible longest p
2017-05-04 00:15:09
205
原创 【70】Climbing Stairs
问题:You 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: Given n will be a
2017-04-23 18:22:40
128
原创 【357】Count Numbers with Unique Digits
题目:Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x Example:Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x 思路:
2017-04-15 21:31:53
226
原创 【338】Counting Bits
题目:Given 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.Example:For nu
2017-04-05 22:47:24
181
原创 【406】 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 o
2017-03-26 22:21:18
152
原创 【513】 Find Bottom Left Tree Value
题目:Given a binary tree, find the leftmost value in the last row of the tree.Example 1:Input:2/ \1 3Output:1Example 2: Input:1/ \2 3/ / \4 5 6/7Output:7
2017-03-19 21:00:56
163
原创 【100】Same Tree && 【104】Maximum Depth of Binary Tree
题目:【100】Same TreeGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have th
2017-03-12 22:21:19
201
原创 【169】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 e
2017-03-05 14:51:00
196
原创 【520】Detect Capital
题目:Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All lette
2017-02-25 16:31:13
342
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人