自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(27)
  • 收藏
  • 关注

转载 1007. 怪兽训练

Problem:贝爷的人生乐趣之一就是约战马会长. 他知道马会长喜欢和怪兽对决,于是他训练了N只怪兽,并对怪兽用0到N-1的整数进行编号. 贝爷训练怪兽的方式是让它们一对一互殴. 两只怪兽互殴会发生以下三种可能的结果:1) 什么事也没发生2) 第一只怪兽永远消失3) 第二只怪兽永远消失怪兽们经过了旷日持久的互殴. 贝爷不知道哪些怪兽进行了互殴也不知道它们互殴的顺

2018-01-08 15:32:10 414

转载 1004. 拓扑序[Special judge]

Problem:在图论中,拓扑序(Topological Sorting)是一个有向无环图(DAG, Directed Acyclic Graph)的所有顶点的线性序列. 且该序列必须满足下面两个条件: 1.       每个顶点出现且只出现一次.2.       若存在一条从顶点 A 到顶点 B 的路径,那么在序列中顶点 A 出现在顶点 B 的前面. 对于一个

2018-01-08 15:27:54 268

原创 1005. 最小和

Problem:从数列A[0], A[1], A[2], ..., A[N-1]中选若干个数,要求对于每个i(0 1  请为下面的Solution类实现解决上述问题的函数minSum,函数参数A是给出的数列,返回值为所求的最小和. class Solution {public:    int minSum(vector& A) {          

2018-01-08 14:47:14 227

原创 1006. 最长公共子串

Problem:给定两个字符串x = x­1x­2…x­n和y = y­1y­2…ym, 请找出x和y的最长公共子串的长度,也就是求出一个最大的k,使得存在下标i和j有x­ix­i+1…x­i+k-1 = yjy­j+1…y­j+k-1. x和y只含有小写字母,长度均在1和1000之间. 请为下面的Solution类实现解决上述问题的函数longestSubstring

2018-01-08 11:31:39 192

原创 1003. 最近的0

Problem:输入一个N*M的01矩阵A,对矩阵的每个位置,求至少经过多少步可以到达一个0. 每一步可以往上下左右走一格. 请为下面的Solution类实现解决这一问题的函数nearestZero,函数参数A为给出的01矩阵,A的行数和列数均不大于100. 函数的返回值是问题的答案. class Solution {public:    vector> neare

2018-01-08 11:30:16 188

原创 1002. 合并二叉树

Problem:输入两个二叉树T1和T2,要求对T1和T2进行合并. 合并是指将二叉树同一位置节点上的数求和,作为合并后二叉树相应位置节点的数值. 如果某个位置上只有一个二叉树有节点,则合并后的二叉树对应位置上的节点上的数值就等于这个节点上的数值.例如:         T1                        T2           1            

2018-01-08 11:28:46 324

原创 1001. 最小差

Problem: 对于一个整数数列A[0], A[1], ..., A[N-1],要求在其中找两个数,使得它们的差的绝对值最小. 2  请实现下面Solution类中计算minDifference(A)的函数,返回值为能得到的最小差. class Solution {public:       int minDifference(vector A) { 

2018-01-08 11:26:10 299

原创 1000. 分组

Problem: 对于一个整数数列A[0], A[1], ..., A[N-1]进行分组,要求每组1到2个数,并且同组之和不能大于w. 求最少可以分成多少组. 1  请实现下面Solution类中计算minPartition(A, w)的函数. class Solution {public:       int minPartition(vector A,

2018-01-08 11:24:44 225

转载 473. Matchsticks to Square

problem:Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsti

2018-01-07 20:55:23 146

原创 Prove that STINGY SAT is NP-complete

Problem:STINGY SAT is the following problem:given a set of clauses(each a disjunction of literals) and an interger k, find a satisfying assignment in which at most k variables are true, if such an a

2017-12-31 11:50:47 506

转载 141. Linked List Cycle

problems:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?solution:using namespace std;   //Definition for singly-l

2017-12-23 15:29:49 149

原创 121. Best Time to Buy and Sell Stock

problem: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 and sell one share

2017-12-23 10:50:24 227

转载 130. Surrounded Regions

problem:Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.Fo

2017-12-17 22:51:17 161

转载 77. Combinations

Problem:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [

2017-12-10 22:45:11 177

转载 717. 1-bit and 2-bit Characters

problem:We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11).Now given a string represented b

2017-11-23 16:10:17 179

转载 129. Sum Root to Leaf Numbers

problem:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number

2017-11-23 15:38:11 146

转载 331. Verify Preorder Serialization of a Binary Tree

Problem:One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value su

2017-11-13 21:20:53 160

转载 687. Longest Univalue Path

Problem:Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the root.Note: The length of path betwe

2017-11-13 20:10:43 281

转载 94. Binary Tree Inorder Traversal

problem:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2].Note: Recursiv

2017-11-13 19:48:52 171

转载 6. ZigZag Conversion

Problem:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H

2017-11-13 17:22:34 173

原创 219. Contains Duplicate II

Problems:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i a

2017-10-29 13:16:13 204

转载 51. N-Queens

Problem:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to t

2017-10-22 22:28:52 140

原创 50. Pow(x, n)

problem:Implement pow(x, n).solution:double myPow(double x, int n) {if (n == 1) return x;if (n == 0) return 1;if (n {x = 1 / x;n = -n;}if (n % 2){return myPow(x, n / 2) * myP

2017-10-01 14:55:18 238

转载 233. Number of Digit One

problem:Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in

2017-10-01 12:46:32 216

原创 104. Maximum Depth of Binary Tree

problem:Given 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.solution:#include

2017-09-24 22:57:26 186

原创 451. Sort Characters By Frequency

Problem:Given a string, sort it in decreasing order based on the frequency of characters.solution:#include#includeusing namespace std;class Solution {public:string frequenc

2017-09-17 23:46:44 181

原创 53.Maximum Subarray

Problem:Find 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 subarray [

2017-09-10 20:34:23 177

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除