自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 算法概论8.8

算法概论8.8问题描述在精确的4SAT(EXACT 4SAT)问题中,输入为一组子句,每个子句都是恰好4个文字的析取,且每个变量最多在每个子句中出现一次。目标是求它的满足赋值——如果该赋值存在。证明精确的4SAT是NP-完全问题。证明考虑通过将3SAT问题归约到4SAT(EXACT 4SAT)问题来验证4SAT(EXACT 4SAT)问题的NP完全性。对于任意一个3SAT实例,考虑其每个子句。若该子

2017-06-28 23:38:31 278

原创 LeetCode OJ 13. Roman to Integer

LeetCode OJ 13. Roman to IntegerDescriptionGiven a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.解题思路罗马数字转换为整数:我们把1,10,100,1000,5,500,500和对应的罗马数字做映射。

2017-05-27 16:42:44 284

原创 LeetCode OJ 12. Integer to Roman

LeetCode OJ 513. Find Bottom Left Tree ValueDescriptionGiven an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.解题思路整数转换为罗马数字,用一个二维数组保存1-9,10-90,100-900

2017-05-27 16:30:36 370

原创 LeetCode OJ 566. Reshape the Matrix

LeetCode OJ 566. Reshape the MatrixDescriptionIn MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’r

2017-05-27 16:05:07 270

原创 LeetCode OJ 62. Unique Paths

LeetCode OJ 62. Unique PathsDescriptionA robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time.

2017-04-25 10:26:23 215

原创 LeetCode OJ 399. Evaluate Division

LeetCode OJ 399. Evaluate DivisionDescriptionEquations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some

2017-04-23 22:33:35 247

原创 LeetCode OJ 239. Sliding Window Maximum

LeetCode OJ 239. Sliding Window MaximumDescriptionGiven an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numb

2017-04-08 21:19:34 219

原创 LeetCode OJ 155. Min Stack

LeetCode OJ 155. Min StackDescriptionDesign a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack.pop() – Removes the element o

2017-04-02 15:41:39 273

原创 LeetCode OJ 503. Next Greater Element II

LeetCode OJ 503. Next Greater Element IIDescriptionGiven 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

2017-03-24 13:02:26 217

原创 LeetCode OJ 496. Next Greater Element I

LeetCode OJ 513. Find Bottom Left Tree ValueDescriptionYou are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nu

2017-03-23 20:03:00 240

原创 NowCoder 剑指Offer_编程题 链表中环的入口节点

NowCoder 链表中环的入口节点Description一个链表中包含环,请找出该链表的环的入口结点。解题思路两个指针p,q从表头出发遍历链表,p每次走一步,q每次走两步。如果链表中有环,那么p,q最终会相遇。设p走了x步,q则走了2x,设环的长度为n,表头到环的入口节点距离为k。那么会有等式2x-x=n,即x=n,即p走过的路程为环的长度。设p此时走了环的距离为d(从入口节点开始算),那么就有k

2017-03-22 13:42:30 336

原创 LeetCode OJ 141. Linked List Cycle

LeetCode OJ 141. Linked List CycleDescriptionGiven a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?解题思路对于判断环的问题,可以采用双指针(快慢指针)的方法来判断。另外,因为题目中给的Lis

2017-03-21 20:30:41 240

原创 LeetCode OJ 160. Intersection of Two Linked Lists

LeetCode OJ 160. Intersection of Two Linked ListsDescriptionWrite a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A:

2017-03-21 19:48:18 208

原创 LeetCode OJ 226. Invert Binary Tree

LeetCode OJ 226. Invert Binary TreeDescriptionInvert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1方法一Recursion: 递归,每一次翻转左右子树。这种方法要每次

2017-03-20 17:35:55 231

原创 LeetCode OJ 50. Pow(x, n)

LeetCode OJ 50. Pow(x, n)DescriptionImplement pow(x, n).解题思路最简单的思路是循环n次,做n次乘法,这样的复杂度是O(n)。但是有一种更好的做法:根据对称性,我们可以把前后n/2个x的乘积看成一个整体,如果n为奇数,则这两部分相乘后只要再乘一次x就是最终结果;否则直接为所求结果。这样一直递归下去,每一次缩小的是当前x集合的1/2。所以时间复杂度

2017-03-14 17:40:22 208

原创 LeetCode OJ 513. Find Bottom Left Tree Value

LeetCode OJ 513. Find Bottom Left Tree ValueDescriptionGiven a binary tree, find the leftmost value in the last row of the tree.Example 1 Input: 2 / \ 1 3 Output: 1Example

2017-03-08 13:53:08 239

原创 LeetCode OJ 406. Queue Reconstruction by Height

LeetCode OJ 406. Queue Reconstruction by HeightDescriptionSuppose 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 t

2017-03-07 16:35:52 221

原创 LeetCode OJ 56. Merge Intervals

LeetCode OJ 56. Merge IntervalsDescriptionGiven a collection of intervals, merge all overlapping intervals.For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18].解题思路这道题的题意是将重叠的区间

2017-03-07 15:43:26 213

原创 LeetCode OJ 240. Search a 2D Matrix II

LeetCode OJ 240. Search a 2D Matrix IIDescriptionWrite an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in

2017-03-06 09:56:59 282

原创 LeetCode OJ 442. Find All Duplicates in an Array

LeetCode OJ 442. Find All Duplicates in an ArrayDescriptionGiven 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 app

2017-02-28 21:48:31 211

原创 LeetCode OJ 207. Course Schedule

LeetCode OJ 207. Course Schedule典型的拓扑排序算法。谨以此题纪念期末机考时没AC这么简单的拓扑排序。upset……ingDescriptionThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for

2017-02-28 20:32:16 284

原创 LeetCode OJ 106. Construct Binary Tree from Inorder and Postorder Traversal

LeetCode OJ 106. Construct Binary Tree from Inorder and Postorder TraversalDescriptionGiven inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do n

2017-02-28 14:24:30 416

原创 LeetCode OJ 105. Construct Binary Tree from Preorder and Inorder Traversal

LeetCode OJ 105. Construct Binary Tree from Preorder and Inorder TraversalDescriptionGiven preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not

2017-02-28 11:40:10 257

原创 LeetCode OJ 515. Find Largest Value in Each Tree Row

LeetCode OJ 515. Find Largest Value in Each Tree RowDescriptionYou need to find the largest value in each row of a binary tree.Example Input: 1 / \ 3 2 / \ \ 5 3 9 O

2017-02-25 14:33:33 347

原创 LeetCode OJ 451. Sort Characters By Frequency

LeetCode OJ 451. Sort Characters By FrequencyDescriptionGiven a string, sort it in decreasing order based on the frequency of characters.Example1 Input: “tree” Output: “eert” Explanat

2017-02-24 20:58:47 437

原创 LeetCode OJ 405. Convert a Number to Hexadecimal

LeetCode OJ 405. Convert a Number to HexadecimalDescriptionGiven an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.Note:All letters in

2017-02-24 16:50:16 230

空空如也

空空如也

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

TA关注的人

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