
Leetcode
文章平均质量分 54
大咸皮蛋
专业老司机,天天发车!
展开
-
LeetCode 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原创 2016-10-30 17:48:23 · 198 阅读 · 0 评论 -
LeetCode 80. Remove Duplicates from Sorted Array II
1.题目描述 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For example, Given sorted array nums = [1,1,1,2,2,3], Your function should return length = 5,原创 2016-11-13 12:39:06 · 191 阅读 · 0 评论 -
LeetCode 148. Sort List
1.题目描述 Sort a linked list in O(n log n) time using constant space complexity. 2.解题思路 我想了一下现有的几种排序,快排,归并。因为这是链表感觉快排不好做吖,涉及了随机访问。然后就想用归并。 归并剩下一个要点就是用快慢指针求这个链表的中点。 3.代码实现 /** * Definition for原创 2016-11-13 10:03:02 · 192 阅读 · 0 评论 -
LeetCode 21. Merge Two Sorted Lists
1.题目描述 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 2.解题思路 最近做题目都想到用递归啊,还有做数论图论的证明题一眼下去就想递归。。呜呜呜原创 2016-11-13 09:45:32 · 180 阅读 · 0 评论 -
LeetCode 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:[ “((()))”, “(()())”, “(())()”, “()((原创 2016-11-10 22:31:08 · 228 阅读 · 0 评论 -
LeetCode 54. Spiral Matrix
题目描述 Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]原创 2016-11-03 17:48:41 · 203 阅读 · 0 评论 -
LeetCode 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: k =原创 2016-11-02 22:40:03 · 238 阅读 · 0 评论 -
LeetCode 112. Path Sum
题目描述 ven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and s原创 2016-10-29 22:31:18 · 223 阅读 · 0 评论 -
LeetCode 16. 3Sum Closest
1.题目描述 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 hav原创 2016-10-29 21:15:30 · 224 阅读 · 0 评论 -
LeetCode 15. 3Sum
题目描述 Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. 解题思路 首先这道题目可以暴力的做,三重循环,复杂度是O(n3)O(n^3)原创 2016-10-27 15:15:46 · 193 阅读 · 0 评论 -
LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal
1. 题目描述 Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 2. 解题思路 这是一道数据结构的题目,给出二叉树的前序和中序遍历结果,从而还原二原创 2017-01-02 15:44:02 · 231 阅读 · 0 评论 -
LeetCode 50. Pow(x, n)
1.题目描述 Implement pow(x, n). 2.解题 思路 这道题目一看感觉诶,还很容易诶,为什么是Medium呢? 然后很快的顺手写了一个上去,分n为0,正负数讨论。 显然,没有AC。 样例错的是,溢出了23333 然后就判断一下溢出嗯~就可以了 3.实现代码 class Solution { public: double myPow(double原创 2016-11-19 23:06:44 · 246 阅读 · 0 评论 -
LeetCode 61. Rotate List2.
1.题目描述 Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL. 2.解题思路 这个题目的意思是移动一个链原创 2016-11-29 16:00:45 · 215 阅读 · 0 评论 -
LeetCode 283. Move Zeroes
1.题目描述 Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For example, given nums = [0, 1, 0, 3, 12], after原创 2016-11-29 16:16:01 · 215 阅读 · 0 评论 -
LeetCode 26. 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 place wit原创 2016-10-24 21:08:54 · 253 阅读 · 0 评论 -
LeetCode 14. Longest Common Prefix
题目描述 Write a function to find the longest common prefix string amongst an array of strings. 解题思路 题目说给定一组字符串让我们找最长的公共前缀。 第一个思路就是暴力的做: 先扫所有串的第一个字符看相等不相等,相等就添加到结果。 直到扫到有不同的的就结束。 复杂度是O(n2)O(n^2) 算法代码原创 2016-10-24 20:42:21 · 182 阅读 · 0 评论 -
LeetCode 9. Palindrome Number
题目描述: Determine whether an integer is a palindrome. Do this without extra space. 算法分析: 题目要求我们对输入的数字,判断一下是不是回文数。 大体的算法: 1. 开一个数组。首先对数字每次都模10,然后把数字保存在数组里面 2. 扫一遍数组,看看是不是对称 注意的点: 负数原创 2016-10-08 15:25:36 · 192 阅读 · 0 评论 -
LeetCode 7. Reverse Integer
题目描述: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 题目分析: 首先这个题目是将一个整数给逆转然后输出,保持符号不变. 大体的思路就是不断地模10,然后加到结果上面.结果再乘10. 几个注意的点原创 2016-10-08 15:04:31 · 185 阅读 · 0 评论 -
LeetCode 1. Two Sum
这是第一篇博客2333333 这是leetcode放在首页的第一道题目 问题描述: 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 h原创 2016-09-07 16:54:04 · 197 阅读 · 0 评论 -
LeetCode 31. Next Permutation
题目描述 Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possi原创 2016-11-03 18:18:53 · 192 阅读 · 0 评论 -
LeetCode 90. Subsets II
1.题目描述 Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. For example, If nums = [1原创 2017-01-01 20:47:59 · 264 阅读 · 0 评论 -
Leetcode 89. Gray Code
1.题目描述 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原创 2017-01-01 20:36:02 · 275 阅读 · 0 评论 -
【算法概论】题目--8.19
1.题目描述 所谓风筝图是这样的,其顶点数为偶数,如2n,且其中的n个顶点构成了一个团,剩余的n个顶点则由一条称为尾巴的路径连接,尾巴的某个端点与团的一个顶点相连。给定一个图和目标g,风筝图问题要求图的一个包含2g个顶点的风筝子图。请证明该问题是NP-完全。 2.解题过程 主要思路:把团问题归约到风筝图问题 【团问题描述】: 给定一个图G,和目标g,求一个有g个顶点的完全图。原创 2016-12-30 13:28:48 · 349 阅读 · 0 评论 -
LeetCode 53. Maximum Subarray
1. 题目描述 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原创 2016-12-02 11:47:46 · 213 阅读 · 0 评论 -
LeetCode 74. Search a 2D Matrix
1.题目描述 Write 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 from left to right.The first int原创 2017-01-14 23:34:56 · 285 阅读 · 0 评论