
算法
healex12138
这个作者很懒,什么都没留下…
展开
-
2. Add Two Numbers
问题:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and r原创 2017-03-02 13:46:41 · 173 阅读 · 0 评论 -
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 例1:F(1, 3) = 6 例2:F(2, 3) = 10 例3:F(10,原创 2017-06-28 16:33:03 · 215 阅读 · 0 评论 -
8.12 K-生成树
问题:k-SPANNING TREE问题是这样的:输入:无向图G=(V, E) 输出:G的一个生成树,其中所有的节点度数都不超过k——如果该树存在。 请证明对任意k>=2: (a)k-生成树问题是一个搜索问题。 (b)k-生成树问题是NP-完全的。(提示:由k=2开始,考虑该问题与Rudrata路径问题的关联。)答:(a) k-生成树问题能够原创 2017-07-01 11:29:52 · 372 阅读 · 0 评论 -
147. Insertion Sort List
问题描述:Sort a linked list using insertion sort.分析:链表插入排序需要建立一个新的链表,按序遍历,让新链表中的合适节点指向新的节点代码:class Solution {public: ListNode* insertionSortList(ListNode* head) { ListNode* new_head原创 2017-06-23 13:55:12 · 154 阅读 · 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原创 2017-06-26 15:13:55 · 182 阅读 · 0 评论 -
238. Product of Array Except Self
问题:Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division a原创 2017-06-26 15:49:25 · 145 阅读 · 0 评论 -
260. Single Number III
问题:Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:原创 2017-06-26 17:59:04 · 164 阅读 · 0 评论 -
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 Solutio原创 2017-06-27 16:55:12 · 1066 阅读 · 0 评论 -
1002. 等价二叉树
问题:两个二叉树结构相同,且对应结点的值相同,我们称这两个二叉树等价. 例如:以下两个二叉树等价 1 1 / \ / \ 2 3 2 3而以下两个则不等价 1 1 / \ / \ 2原创 2017-06-27 18:21:29 · 231 阅读 · 0 评论 -
113. Path Sum II
问题描述:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5原创 2017-05-31 18:40:11 · 188 阅读 · 0 评论 -
102. Binary Tree Level Order Traversal
问题描述:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3原创 2017-05-31 17:27:12 · 174 阅读 · 0 评论 -
456.132 Pattern
问题:Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such that i j kand ai < ak < aj. Design an algorithm that takes a list of n numbers as原创 2017-02-24 21:39:11 · 188 阅读 · 0 评论 -
5. Longest Palindromic Substring
问题描述:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.分析:需要以每一个字母开始去遍历寻找与随后的字母是否构成回文:1、构成回文,则判断长度是否比之前的会问长度更长:1)若比之前的回文长度更长,原创 2017-03-09 20:17:58 · 244 阅读 · 0 评论 -
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 NA P原创 2017-03-26 21:56:12 · 170 阅读 · 0 评论 -
25.Reverse Nodes in k-Group
问题: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-03-18 19:00:18 · 167 阅读 · 0 评论 -
10. Regular Expression Matching
问题描述:Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire原创 2017-04-03 21:50:23 · 176 阅读 · 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.De原创 2017-05-10 19:53:08 · 155 阅读 · 0 评论 -
56. Merge Intervals
问题:Given 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].Subscribe to see which companies asked原创 2017-05-10 21:01:44 · 177 阅读 · 0 评论 -
16. 3Sum Closest
问题:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have原创 2017-05-03 19:07:34 · 164 阅读 · 0 评论 -
1003. 相连的1
问题:对于一个01矩阵A,求其中有多少片连成一片的1. 每个1可以和上下左右的1相连. 请为下面的Solution类实现解决这一问题的函数countConnectedOnes,函数参数A为给出的01矩阵,A的行数和列数均不大于1000. 函数的返回值是问题的答案. 例1:A=100010001答案为3. 例2:A=1101010111原创 2017-06-28 10:44:33 · 202 阅读 · 0 评论