自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 LeetCode: Partition Equal Subset Sum

题目 Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note: Each of the array elem

2017-01-08 15:44:34 364

原创 LeetCode: Ones and Zeroes

题目: In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.For now, suppose you are a dominator of m 0s and n 1s respectively. On the othe

2017-01-08 15:31:50 371

原创 LeetCode: Matchsticks to Square

题目: Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You s

2017-01-07 20:55:41 307

原创 LeetCode: Matchsticks to Square

题目: Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You s

2017-01-07 20:08:58 288

原创 LeetCode: Remove K Digits

题目: Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible.Note: The length of num is less than 10002 and will be ≥

2017-01-07 19:06:57 455

原创 《算法概论》8.8

题目: 在精确的4SAT(EXACT 4SAT)问题中,输入为一组自居,每个字句都是恰好4个文字的析取,且每个变量最多在每个字句中出现一次。目标是求它的满足赋值——如果该赋值存在。证明精确的4SAT是NP完全问题。证明: 用归约来证明:如果问题A可以归约到问题B,记作A->B,如果A是NP完全问题,则通过归约证明B也是NP完全问题。即问题的难度是通过箭头的方向传递的。现在要证明EXACT 4SA

2016-11-26 16:55:10 484

原创 LeetCode: Count Numbers with Unique Digits

题目: Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, ex

2016-11-14 17:35:46 176

原创 LeetCode: Triangle

题目: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle [ [2], [3,4],

2016-11-12 12:23:10 284

原创 LeetCode: Course Schedule

题目: There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as

2016-11-07 14:41:40 204

原创 LeetCode: Word Break

题目: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, given s = “leetcode”, dict = [“leet”

2016-11-01 15:55:42 328

原创 LeetCode: Candy

题目: There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least on

2016-11-01 14:11:50 277

原创 LeetCode: Multiply Strings

题目: Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative. Converting the input string to integer

2016-10-31 20:17:47 205

原创 LeetCode: 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 the arra

2016-10-31 17:37:11 190

原创 LeetCode: Divide Two Integers

题目: Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT.题目很有意思,要求在不做乘法、除法、取余运算的条件下求两个除数相除的结果。 首先想到的是做减法,用一个变量标记两数相除的结果的正负(两数同号为正,异号为负),然后把除

2016-10-30 21:50:17 278

原创 LeetCode: Integer to Roman

做了罗马数字转整数的问题后,再称热打铁做了一道镜像问题:整数转罗马数字,其中,给定的整数范围为1~3999。罗马数字字符I、V、X、L、C、D、M分别表示1、5、10、50、100、500、1000,如果直接以上面的数字为单位对给定的整数取位再转化为罗马数字,很容易出错。不如先用罗马数字来表示我们熟悉的十进制的各个位,再对给定的整数取十进制下的位,然后找出对应位上的罗马数字表示法,加到结果中。代码:

2016-10-29 23:56:04 261

原创 LeetCode: Roman to Integer

题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.题目给定一个字符组成的罗马数字,要求把这个罗马数字转化为整数。答题之前,需要先了解一下罗马数字的表示: 在罗马数字中,I,V,X,L,C,D,M分别表示阿拉伯数字的1,5,1

2016-10-29 17:01:40 276

原创 LeetCode: Split Array Largest Sum

题目: Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these m

2016-10-19 17:58:37 265

原创 LeetCode: Is Subsequence

题目: Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) strin

2016-10-17 18:13:50 223

原创 LeetCode: Arithmetic Slices

题目: A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequenc

2016-10-17 17:41:01 218

原创 LeetCode: Longest Increasing Subsequence

题目: Given an unsorted array of integers, find the length of longest increasing subsequence.For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101], ther

2016-10-13 17:58:29 218

原创 LeetCode: 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 stock),

2016-10-13 00:01:39 190

原创 LeetCode: 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-10-12 17:50:45 175

原创 LeetCode: Combination Sum

题目一: Given a set of candidate numbers (C) 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 from C unlimited numbe

2016-10-11 15:55:17 204

原创 LeetCode: 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], [3,1,2], [3

2016-10-11 14:45:01 248

原创 LeetCode: Number of Islands

题目: Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may as

2016-10-06 00:50:13 155

原创 LeetCode: Reverse Integer

题目: Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321这道题很简单,从低位向高位取整数每位上的数字,并把初始化为0的result值乘10加上这个取得的数字,时间复杂度为o(logn)。但是这里要特别注意整数范围的问题,因为一个整数的倒序很可能会溢出。代码:clas

2016-10-03 23:53:54 397

原创 LeetCode: Binary Tree Paths

题目: Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: All root-to-leaf paths are:[“1->2->5”, “1->3”]这一题是最基础的深搜题,要我们列出一棵二叉树从根到所有叶子的路径。用递归来实现非常简单,但要注意解的格式

2016-09-24 15:20:19 205

原创 LeetCode: Decode String

题目: Given an encoded string, return it’s decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is g

2016-09-22 00:34:46 440

原创 LeetCode: Burst Balloons

题目: Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get num

2016-09-21 17:24:54 179

原创 LeetCode: Search a 2D Matrix II

题目: 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 in ascending from left to right. Integers in ea

2016-09-19 21:01:55 185

原创 LeetCode: Majority Element

题目: Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element al

2016-09-19 19:56:15 285

原创 LeetCode: Different Ways to Add Parentheses

题目: Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Example 1 In

2016-09-14 17:15:38 235

原创 LeetCode: Kth Largest Element in an Array

题目: Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example, Given [3,2,1,5,6,4] and k = 2, return 5.N

2016-09-11 14:58:26 208

原创 LeetCode: Maximum Subarray

问题: 这是一个最大子序列和的问题,首先需要明确子序列是连续的。一个长度为n的序列中有n(n+1)/2个子序列,所以如果用穷举法(暴力搜索)的话,时间复杂度至少为o(n^2),所以需要探寻更高效的算法。解法一: 分治法:将序列一分为二,那么能得到最大值的子序列可能在左边的序列中,可能在右边的序列中,也可能一半在左边的序列,一半在右边的序列中,比较这三个值的大小,输出最大的值。

2016-09-10 21:06:30 213

原创 LeetCode: ZigZag Conversion

题目: ZigZag指的是将字符串按Z字形(锯齿形)排列,如字符串“123456789”,当numRows为3时,排列顺序如下图: 题目要求我们将字符串按锯齿形排列后按行重新组合,如上面的例子,新组合的字符串为“0481357926”。解法一: 为每一行申请一个字符串保存重新排列后的字符,数字按Z字形铺排时有两个方向,数值向下和斜向上,用布尔变量forth来保存当前方向:向下时字符串数

2016-09-05 23:30:18 229

原创 LeetCode: Two Sum

LeetCode: Two Sum题目: 解法一: 二层搜索,对每一个元素,在该元素之后的序列中搜索与之相加和为targetd的元素,时间复杂度为O(n^2),Accepted的代码如下:class Solution{public: vector<int> twoSum(vector<int>& nums,int target){ vector<int> results;

2016-09-04 17:20:07 256

空空如也

空空如也

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

TA关注的人

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