
leetcode
文章平均质量分 60
梦逝星痕
这个作者很懒,什么都没留下…
展开
-
[leetcode]315. Count of Smaller Numbers After Self
问题描述 You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i]. E原创 2016-07-20 11:04:39 · 496 阅读 · 0 评论 -
[编程之美]区间重合判断
编程之美2.19,在网上看见很多答案但是并没有看见java版本的,所以自己写一个。问题描述: 给定一个源区间[x, y] (y>=x)和N个无序的目标区间[x1,y1],[x2,y2],[x3,y3],……[xN,yN],判断源区间[x,y]是不是在目标区间内? 例如给定源区间[1,6]和一组无序的目标区间[2,3],[1,2],[2,9],[3,4],即可认为区间[1,6]在区间[2,3原创 2016-06-23 11:01:02 · 876 阅读 · 0 评论 -
[leetcode]Single Number
刷微博时看见的一道网易面试题,竟然一点印象都没有,后来才知道是leetcode上面的原题,而且是一个系列的都是关于位运算的。136. Single Number Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorit原创 2016-06-20 21:35:08 · 451 阅读 · 0 评论 -
[编程之美]中国象棋将帅问题
编程之美1.2, 题目不再重复了,这里主要研究方法二。核心思想就是两重循环分别从1到9,如果两个变量处于同一直线则跳过,不然就打印出两个变量。题目的要求在于只能用一个字节来存储,所以就需要空间上进行巧妙的变换。两个变量从1到9,其实只有9*9=81种状态,理论上一个字节存储已经绰绰有余了。题中方法二给出的解法就是将AB的状态转换为两位9进制的数,低位的数值i%9代表A的状态,高位数值i/9代表B的状原创 2016-07-10 11:11:21 · 332 阅读 · 0 评论 -
[编程之美]一摞烙饼的排序
原文博客写的相当全面,这里不在粘贴。求最优问题,要想到动态规划、贪心和分支界限算法。这道题属于典型的分支界限,原理类似与穷举法,但是通过穷举过程中不断放弃一些不可能的子树来提高搜索效率,即用到人工智能课上讲到的剪枝算法。剪纸主要通过提高下届值和降低上界值。原文博客中介绍的非常详细,不在赘述了。转载 2016-07-10 20:07:07 · 457 阅读 · 0 评论 -
198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house原创 2016-05-11 10:14:23 · 271 阅读 · 0 评论 -
31. Next Permutation
参考地址 http://www.mamicode.com/info-detail-650903.html首先,关于什么是全排列不做解释。如果一个排列为A,下一个排列为A_NEXT,那么A_NEXT一定与A有尽可能长的公共前缀。看具体例子,一个排列为124653,如何找到它的下一个排列,因为下一个排列一定与124653有尽可能长的前缀,所以,脑洞大开一下,从后面往前看这转载 2016-05-09 09:03:09 · 337 阅读 · 0 评论 -
[编程之美]阶乘问题
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.1、分解因子, 当且仅当 因子中出现 一对 (2,5)时, 最后结果会增加一个 trailing zero.2、2的个数原创 2016-04-26 10:35:51 · 524 阅读 · 0 评论 -
3. 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 answer is "原创 2016-05-05 16:15:34 · 338 阅读 · 0 评论 -
330. Patching Array
Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements in the array. Re转载 2016-05-27 10:22:15 · 262 阅读 · 0 评论 -
50. Pow(x, n)
最开是在剑指offer上面看到这道题,今天遇到试了一下发现不可以,上网找了一下才发现还有更巧妙的方法。Consider the binary representation of n. For example, if it is "10001011", then x^n = x^(1+2+8+128) = x^1 * x^2 * x^8 * x^128. Thus, we don't w原创 2016-05-13 15:04:21 · 325 阅读 · 0 评论 -
91. Decode Ways
参考地址 https://segmentfault.com/a/1190000003813921Decode WaysA message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26转载 2016-05-13 11:22:00 · 285 阅读 · 0 评论 -
[算法学习]最长回文子串:Manacher算法
参考地址:http://www.cnblogs.com/bitzhuwei/p/Longest-Palindromic-Substring-Part-II.html#_label1首先我们把字符串S改造一下变成T,改造方法是:在S的每个字符之间和S首尾都插入一个"#"。这样做的理由你很快就会知道。例如,S="abaaba",那么T="#a#b#a#a#b#a#"。转载 2016-05-06 16:53:00 · 430 阅读 · 0 评论 -
300. Longest Increasing Subsequence
最长升序子序列,很经典的问题,发现写博客的真是不负责任啊,瞎写一通根本没有任何逻辑,本文主要参考http://yzmduncan.iteye.com/blog/1546503,加上自己的理解和实现的代码。最长递增子序列问题:在一列数中寻找一些数,这些数满足:任意两个数a[i]和a[j],若i设dp[i]表示以i为结尾的最长递增子序列的长度,则状态转移方程为:dp[i] =原创 2016-05-13 10:06:05 · 353 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock
public int maxProfit(int[] prices) { if(prices.length<2){ return 0; } int re=0; int low=prices[0]; for(int i=1; i<prices.length; i++){ if(prices[i]<low原创 2016-05-10 15:22:52 · 306 阅读 · 0 评论 -
[编程之美]买票找零(卡特兰数)
第一次看这题的时候没有好好注意,后来发现这是一类大问题,学习了卡特兰数这个概念,顺便又复习了高中的排列组合知识、、、一、书中问题先看一下书中引入卡特兰数的例子: 《编程之美》4.3买票找零:2n个人排队买票,其中n个人持50元,n个人持100元。每张票50元,且一人只买一张票。初始时售票处没有零钱找零。请问这2n个人一共有多少种排队顺序,不至于使售票处找不开钱?分析1:队伍的序号标为0,1,…原创 2016-07-31 12:13:12 · 3437 阅读 · 0 评论