C++代码
lihuixuaaa
这个作者很懒,什么都没留下…
展开
-
6:ZigZag Conversion(锯齿形的转换)
问题描述 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 N A P L S I原创 2017-09-23 19:30:04 · 544 阅读 · 0 评论 -
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. Determine原创 2017-11-19 13:49:06 · 156 阅读 · 0 评论 -
62. Unique Paths
问题描述 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. The robot is trying to reach th原创 2017-11-19 14:09:39 · 133 阅读 · 0 评论 -
39. Combination Sum
问题描述 Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen f原创 2017-11-05 19:28:50 · 119 阅读 · 0 评论 -
59.Spiral Matrix II
问题描述 Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example, Given n = 3, You should return the following matrix: [ [ 1, 2, 3 ], [ 8,原创 2017-11-05 20:02:14 · 139 阅读 · 0 评论 -
131. Palindrome Partitioning
问题描述 Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s. For example, given s = “aab”, Return [ [“aa”,”b原创 2017-12-10 15:17:56 · 139 阅读 · 0 评论 -
139. Word Break
问题描述 Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. You may原创 2017-12-10 17:00:10 · 156 阅读 · 0 评论 -
89. Gray Code
问题描述 The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence原创 2017-12-02 19:27:54 · 123 阅读 · 0 评论 -
137.Single Number II
问题描述 Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Cou原创 2017-12-02 19:55:23 · 205 阅读 · 0 评论 -
40. Combination Sum II
问题描述 Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in the combin原创 2017-11-24 22:00:27 · 121 阅读 · 0 评论 -
73. Set Matrix Zeroes
问题描述 Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow up: Did you use extra space? A straight forward solution using O(mn) space is probably a ba原创 2017-11-24 22:12:06 · 134 阅读 · 0 评论 -
153. Find Minimum in Rotated Sorted Array
问题描述 Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no dup原创 2017-12-24 12:04:34 · 145 阅读 · 0 评论 -
216. Combination Sum III
问题描述 Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Example 1: Input:原创 2017-12-24 12:53:54 · 164 阅读 · 0 评论 -
223. Rectangle Area
问题描述 Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total原创 2017-12-26 13:32:38 · 170 阅读 · 0 评论 -
147. Insertion Sort List
问题描述 Sort a linked list using insertion sort.解题思路 该问题比较简单,要求我们用插入排序的方法实现链表的排序。 插入排序即遍历链表,然后将其插入到适当的为值即可,我们可以将链表分为两部分,前半部分为已经排序好的,后半部分是还未排序的,用指针指向未排序的头结点,然后遍历排序号的部分,找到第一个大于该值的节点,然后将其插入到该节点之前一个位置即可。然后原创 2017-12-17 19:36:46 · 257 阅读 · 0 评论 -
144. Binary Tree Preorder Traversal
问题描述Given a binary tree, return the preorder traversal of its nodes’ values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,2,3]. Note: Recursive solu原创 2017-12-17 19:52:15 · 127 阅读 · 0 评论 -
75. Sort Colors
问题描述 Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers原创 2017-11-12 14:22:54 · 130 阅读 · 0 评论 -
64. Minimum Path Sum
问题描述 Given 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 move either down or right a原创 2017-11-12 14:01:48 · 158 阅读 · 0 评论 -
600. Non-negative Integers without Consecutive Ones
问题描述 Given a positive integer n, find the number of non-negative integers less than or equal to n, whose binary representations do NOT contain consecutive ones. Example: Input: 5 Output: 5 Explana原创 2017-10-14 22:26:45 · 187 阅读 · 0 评论 -
17:Letter Combinations of a Phone Number(字母组合的电话号码)
问题描述 Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit s原创 2017-09-17 11:29:41 · 312 阅读 · 0 评论 -
12:Integer to Roman(数字转为罗马数字)
问题描述 Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.解题思路 题目的要求为输入1~3999范围之间的整数,将其转化为罗马数字的形式。首先问们要知道罗马数字的基本表示: 1~9: {“I”, “II”, “III”,原创 2017-09-10 10:42:03 · 608 阅读 · 0 评论 -
42. 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,2,1,0,1,3,2,1,2原创 2017-09-23 20:39:54 · 278 阅读 · 0 评论 -
25. Reverse Nodes in k-Group(链表k-组反转)
问题描述 Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the number原创 2017-09-29 16:54:29 · 211 阅读 · 0 评论 -
45. Jump Game II(跳跃游戏II)
问题描述 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. Your goal原创 2017-09-29 17:51:58 · 1182 阅读 · 0 评论 -
19. Remove Nth Node From End of List(移除链表的倒数第n个节点)
问题描述 Given a linked list, remove the nth node from 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, the linke原创 2017-10-01 09:59:30 · 357 阅读 · 0 评论 -
41. First Missing Positive(第一个缺失的正数)
问题描述 Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. Your algorithm should run in O(n) ti原创 2017-10-05 11:03:29 · 471 阅读 · 0 评论 -
128. Longest Consecutive Sequence(最长连续序列)
问题描述 Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [1, 2原创 2017-10-05 11:49:33 · 269 阅读 · 0 评论 -
517. Super Washing Machines(超级洗衣机)
问题描述 You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty. For each move, you could choose any m (1 ≤ m ≤ n) washing machines, and pass one dress原创 2017-10-05 12:24:21 · 1061 阅读 · 0 评论 -
22. Generate Parentheses
问题描述 Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ “((()))”, “(()())”, “(())(原创 2017-10-29 13:33:55 · 177 阅读 · 0 评论 -
46. Permutations
问题描述 Given a collection of distinct numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1],原创 2017-10-29 14:16:39 · 166 阅读 · 0 评论 -
24. Swap Nodes in Pairs
问题描述 Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space.原创 2017-10-22 13:11:11 · 133 阅读 · 0 评论 -
34. Search for a Range
问题描述 Given an array of integers sorted in ascending order, find the starting and ending position of a given target value. Your algorithm’s runtime complexity must be in the order of O(log n). If the原创 2017-10-22 13:46:46 · 148 阅读 · 0 评论 -
48. Rotate Image
问题描述 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, which means you have to modify the input 2D mat原创 2017-10-22 14:22:22 · 148 阅读 · 0 评论 -
683. K Empty Slots
问题描述 There is a garden with N slots. In each slot, there is a flower. The N flowers will bloom one by one in N days. In each day, there will be exactly one flower blooming and it will be in the status原创 2017-10-14 20:54:30 · 382 阅读 · 0 评论 -
算法概论习题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.原创 2018-01-02 22:31:18 · 404 阅读 · 0 评论