自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 算法证明题8.12 k生成树问题为搜索问题和NPC问题

题目:k生成树问题描述如下:输入:无向图G=(V,E);输出:G的一个生成树,其中所有结点的度数都不超过k(如果存在的话);证明:对于k>=2,有1)k生成树问题为搜索问题2)k生成树问题为NPC问题证明如下:1)首先要验证所找的生成树是否符合要求,只需要遍历每个点,检查其度数即可,时间复杂度为V+E,为多项式时间复杂度,因此k-生成树问题为NP问题。2

2017-07-06 21:05:30 493

原创 LeetCode6. 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

2017-07-06 19:07:40 281

原创 LeetCode5. 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.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answ

2017-06-27 22:05:57 291

原创 LeetCode33. Search 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).You are given a target value to search.

2017-06-22 16:17:34 278

原创 LeetCode38. Count and Say

题目The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11

2017-06-19 18:21:36 279

原创 LeetCode28. Implement strStr()

题目Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.思路就是一个找子串的函数。先顺势扫描,寻找首字母的匹配项,之后利用subString函数看剩余串是否匹配,如果匹

2017-06-06 11:04:19 256

原创 LeetCode27. Remove Element

题目Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant mem

2017-06-04 22:37:57 184

原创 LeetCode26. Remove Duplicates from Sorted Array

题目Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in pl

2017-05-25 21:58:03 172

原创 LeetCode24. 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

2017-05-18 10:44:01 360

原创 LeetCode19. Remove Nth Node From End of List

题目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

2017-05-10 00:16:17 321

原创 LeetCode13. Roman to Integer

题目Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.思路百度一下,查到罗马数字与int转换的对应表那么问题就简单了,我们把String类型拆分为一个一个的char类型,查表对应到相应的阿拉伯数

2017-05-06 13:56:17 346

原创 LeetCode12. Integer to Roman

题目Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.思路先百度一下,查看罗马数字(String表示)与int类型之间的转换这样代码就很好编写了,我们只要按照int类型的每一位的数字,将其查表转

2017-05-06 13:50:59 251

原创 LeetCode2.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

2017-04-28 16:42:51 248

原创 LeetCode121. Best Time to Buy and Sell Stock

题目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 of the

2017-04-20 16:25:16 248

原创 LeetCode100. Same Tree

题目Given 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 the same value.附:结点

2017-04-14 16:22:11 245

原创 LeetCode20. Valid Parentheses

题目Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are

2017-04-08 14:41:10 210

原创 LeetCode3. Longest Substring Without Repeating Characters

题目Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the ans

2017-03-31 19:49:03 268 3

原创 leetCode75. 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 i

2017-03-24 18:01:52 281

原创 LeetCode48. Rotate Image

题目You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?思路题目关键在于找到旋转时的对应关系即可,先复制一遍矩阵,然后对于点[i][j

2017-03-24 17:58:00 246

原创 LeetCode70. 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 b

2017-03-17 11:23:24 383

原创 LeetCode67. Add Binary

题目Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".Subscribe to see which companies asked this question.思路由于加

2017-03-17 11:17:32 272

原创 LeetCode35. Search Insert Position

题目Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in th

2017-03-08 16:56:22 219

原创 LeetCode14. Longest Common Prefix

题目Write a function to find the longest common prefix string amongst an array of strings.思路首先找出数组的String最小长度,避免index越界。之后从i=0开始遍历所有数组中的String的i位,检查是否相等,若相等则最大前缀+1,若不相等则退出循环,返回最大前缀代码

2017-03-08 16:50:17 265

原创 LeetCode9. Palindrome Number

题目Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of c

2017-02-28 16:47:58 298

原创 LeetCode1. Two Sum

题目Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use

2017-02-28 15:30:13 186

空空如也

空空如也

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

TA关注的人

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