- 博客(250)
- 资源 (2)
- 收藏
- 关注
原创 LeetCode—416. Partition Equal Subset Sum
Partition Equal Subset Sum思路:爆破+剪枝,核心的2点,1,从大到小开始排列,2如果从某个位置开始之后所有的数加起来都不能达到目标值,则整个后面所有的2^n的可能性都不必再测试了。GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢
2016-10-13 16:52:47 492
原创 LeetCode—409. Longest Palindrome
Longest Palindrome思路:非常简单,随便写GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { public int longestPalindrome(String s)
2016-10-09 17:03:19 470
原创 LeetCode—417. Pacific Atlantic Water Flow
Add Strings思路:注意理解一下题目,求的是可以同时去往两边的点,(显然左下角和右上角肯定是符合的),查找一下即可,注意记得标记访问过的点,很普通的题目。GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solut
2016-10-09 16:38:57 1457
原创 LeetCode—415. Add Strings
Add Strings思路:很简单,别用递归GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { public String addStrings(String num1, String num2
2016-10-09 14:18:05 1276
原创 LeetCode—161. One Edit Distance
Binary Tree Upside Down思路:其实分类讨论更容易一次过,考虑长度相等和差1的情况,特别注意,s.equals(t)是falseGitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution {
2016-09-29 19:39:44 578
原创 LeetCode—156. Binary Tree Upside Down
Binary Tree Upside Down思路:显然是递归去做的GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。/** * Definition for a binary tree node. * public class TreeNod
2016-09-29 14:36:49 544
原创 LeetCode—406. Queue Reconstruction by Height
Queue Reconstruction by Height思路:随便找个方式排序,然后再按照插入排序找他们的位置,我选择的是先按k排顺序,k相同按h排顺序GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solu
2016-09-27 14:19:51 1675
原创 LeetCode—405. Convert a Number to Hexadecimal
Convert a Number to Hexadecimal思路:改成long,负数求出对应的数值,再处理GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { public String toH
2016-09-27 11:27:02 1023
原创 LeetCode—404. Sum of Left Leaves
Sum of Left Leaves思路:智障题目GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。/** * Definition for a binary tree node. * public class TreeNode {
2016-09-27 10:47:21 873
原创 LeetCode—400. Nth Digit
Nth Digit思路:好像不用动态规划也能实现。GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { public int findNthDigit(int n) { int lengt
2016-09-21 10:00:01 876
原创 LeetCode—403. Frog Jump
Frog Jump思路:好像不用动态规划也能实现。GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { int[] stones; int[][] ans; public bool
2016-09-19 13:24:43 1218
原创 LeetCode—402. Remove K Digits
Binary Watch思路:贪心算法,本来写的而是递归,然后栈溢出了,改成循环了。GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { public String removeKdigits(S
2016-09-19 13:15:55 552
原创 LeetCode—401. Binary Watch
Binary Watch思路:打表。GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { Map> minuteMap = new HashMap>() { {
2016-09-19 10:13:02 831
原创 LeetCode—390. Elimination Game
Elimination Game思路:逐个删除的思路肯定是超时的。注意到第一次1……n从左到右删除后剩下的是2,4,6,8……这个问题等效于1……n/2(向下取证)从右往左的答案*2。那么再考虑从右往左1……2k+1,和从左往右的效果是等同的,1……2k,则剩下1,3,5,7,9,……等效于2a-1那么可以递归求解。GitHub地址:https://gi
2016-09-18 12:06:55 2645
原创 LeetCode—398. Random Pick Index
Integer Replacement思路:注意The array size can be very large. Solution that uses too much extra space will not pass the judge.不能开辟额外空间,所以更换随机方式。GitHub地址:https://github.com/corpse
2016-09-12 17:52:57 914
原创 LeetCode—396. Rotate Function
Integer Replacement思路:F[i]=F[i-1]+sum-n*A[n-i]GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { public int maxRotateFunct
2016-09-12 17:45:52 642
原创 LeetCode—397. Integer Replacement
Integer Replacement思路:动态规划,注意各种边界条件GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { Map map; public int integerRepla
2016-09-12 16:32:45 873
原创 LeetCode—167. Two Sum II - Input array is sorted
Two Sum II - Input array is sorted思路:弱智题目GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { public int[] twoSum(int[]
2016-09-09 16:39:12 364
原创 LeetCode—391. Perfect Rectangle
Perfect Rectangle思路:核心思路2点:1,存储每个点,求出最后只出现奇数次的。判断最后是否只剩下4个。2.求每个矩形的总面积,判断是否和最后4个点构成的面积相等(防止内部重叠)GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public
2016-09-08 16:07:36 600
原创 LeetCode—394. Decode String
Decode String思路:先遍历String,找到少于k的字母,然后以这些字母split字符串,再将字符串递归调用方法。GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { public i
2016-09-07 11:20:12 370
原创 LeetCode—394. Decode String
Decode String思路:逐个char解析即可GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { public String decodeString(String s) {
2016-09-06 10:59:39 842
原创 LeetCode—393. UTF-8 Validation
UTF-8 Validation思路:很简单,看注释即可。GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { public boolean validUtf8(int[] dat
2016-09-06 09:58:04 663
原创 LeetCode—392. Is Subsequence
Is Subsequence思路:贪心算法,直接两个index去逐个比较s和t即可。GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { public boolean isSubsequence(
2016-09-06 09:29:39 748
原创 LeetCode—389. Find the Difference
Find the Difference思路:建立一个长度26的数组,循环字符串s和t即可。GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { public char findTheDifference(
2016-08-29 10:01:48 708
原创 LeetCode—388. Longest Absolute File Path
Longest Absolute File Path思路:非常恶心的题目,测试样例提供一个不从某个目录开始,而是从多个目录开始的样例。。题目很简单,注意各种奇怪的案例即可。GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public cl
2016-08-22 17:48:09 1328
原创 LeetCode—387. First Unique Character in a String
First Unique Character in a String思路:非常简单,一个list存,一个map记录下标。GitHub地址:https://github.com/corpsepiges/leetcode点此进入如果可以的话,请点一下star,谢谢。public class Solution { public int fi
2016-08-22 15:35:48 568
原创 LeetCode—386. Lexicographical Numbers
Lexicographical Numbers思路:最直观的思路就是分治,但是太无趣了。直接上计数。把每个数当做11进制来看,先确定好数的范围,根据n可以知道最大为k位数,然后把每个数都转成11进制,不足k位的后面补x补齐。每个位置上面,x表示0,其他10个数字表示自身+1,这是一个11进制,然后转化成10进制即可知道位置。GitHub地址:https:
2016-08-22 15:05:31 1792
原创 LeetCode—385. Mini Parser
Mini Parser思路:1.首先根据是否有括号判定是否为纯数字,如果是纯数字则直接转化。2其次判断list是否为空,为空直接转化。3.统计左右括号是否对应,如果对应,则遇到逗号后递归处理,无论是list还是纯数字。GitHub地址:https://github.com/corpsepiges/leetcode目前java版本的答案大约进度是免费的差40题,p
2016-08-15 11:25:31 2313
原创 LeetCode—384. Shuffle an Array
Shuffle an Array思路:随机化下标。然后重新获取值。GitHub地址:https://github.com/corpsepiges/leetcode目前java版本的答案大约进度是免费的差40题,python大约是一半,其他的等以后再补充。点此进入如果可以的话,请点一下star,谢谢。public class Sol
2016-08-12 11:29:47 1836
原创 LeetCode—383. Ransom Note
Linked List Random Node思路:拆解成char,然后统计所有的char个数GitHub地址:https://github.com/corpsepiges/leetcode目前java版本的答案大约进度是免费的差40题,python大约是一半,其他的等以后再补充。点此进入如果可以的话,请点一下star,谢谢。publ
2016-08-12 11:16:05 563
原创 LeetCode—382. Linked List Random Node
Linked List Random Node思路:常数空间求随机元素,显然不能用队列存储,那么利用公式第i个元素取到的概率等于 1/i,他被保留的概率等于 1/i*(i/(1+i))*.......*(n-1/n)=1/nGitHub地址:https://github.com/corpsepiges/leetcode目前java版本的答案大约进度是免
2016-08-12 10:55:58 1011
原创 LeetCode—381. Insert Delete GetRandom O(1) - Duplicates allowed
Insert Delete GetRandom O(1) - Duplicates allowed 思路:java中的list提供了针对制定元素删除的方法以及判断该元素是否存在的方法GitHub地址:https://github.com/corpsepiges/leetcode目前java版本的答案大约进度是免费的差40题,python大约是一半,其他的等以后再
2016-08-09 10:18:00 1022 2
原创 LeetCode—380. Insert Delete GetRandom O(1)s
Insert Delete GetRandom O(1)思路:java中的list提供了针对制定元素删除的方法以及判断该元素是否存在的方法GitHub地址:https://github.com/corpsepiges/leetcode目前java版本的答案大约进度是免费的差40题,python大约是一半,其他的等以后再补充。点此进入如果可以的话,请点一下st
2016-08-08 15:08:20 837
原创 LeetCode—378. Kth Smallest Element in a Sorted Matrix
Kth Smallest Element in a Sorted Matrix思路:1.首先这题把所有的数组遍历出来然后直接排序就可以AC..... 2.正常思路就是维系最大堆。GitHub地址:https://github.com/corpsepiges/leetcode目前java版本的答案大约进度是免费的差40题,python大约是一半,其他的等以后再补充。
2016-08-02 10:20:37 3027
原创 LeetCode—376. Wiggle Subsequence
Wiggle Subsequence思路:贪心算法,每次只要跟前一个比,如果符合条件,则获取,如果不符合条件,说明提升了可以比较的空间GitHub地址:https://github.com/corpsepiges/leetcode目前java版本的答案大约进度是免费的差40题,python大约是一半,其他的等以后再补充。点此进入如果可以的话,请点一下star,谢
2016-07-26 10:04:33 608
原创 LeetCode—377. Combination Sum IV
Combination Sum IV思路:动态规划。GitHub地址:https://github.com/corpsepiges/leetcode目前java版本的答案大约进度是免费的差40题,python大约是一半,其他的等以后再补充。点此进入如果可以的话,请点一下star,谢谢。public class Solution { p
2016-07-25 12:08:55 1632
原创 LeetCode—375. Guess Number Higher or Lower II
Guess Number Higher or Lower II思路:刚开始的时候想到的不是动态规划,而是在(s,e)的范围内求出m,使得(s,m-1)=(m+1,e),结果发现两个问题,一个是不能使得两边相等时m靠左还是右,第二个问题更严重,因为题目中表示最后猜对的那一次是不要成本的。。。后来参考下,还是用dp来做。动态规划方程:matrix[s][e]=m+Math.max(matrix[s
2016-07-18 17:09:46 2018
原创 LeetCode—374. Guess Number Higher or Lower
Guess Number Higher or Lower思路:非常简单,就是二分法,注意二分的时候别超过int上限即可。GitHub地址:https://github.com/corpsepiges/leetcode点此进入/* The guess API is defined in the parent class GuessGame. @param n
2016-07-13 15:22:05 628
原创 LeetCode—372. Super Pow
Super Pow思路:利用两条公式 (ak+b)(ck+d)%k=bd; a^b(假设b为偶数)=(a^(b/2))*a^(b/2);GitHub地址:https://github.com/corpsepiges/leetcode点此进入public class Solution { public int superPow(int
2016-07-12 09:46:58 632
原创 LeetCode—373. Find K Pairs with Smallest Sums
Find K Pairs with Smallest Sums思路:最简单的方法,写一个比较规则,直接比较GitHub地址:https://github.com/corpsepiges/leetcode点此进入public class Solution { public List kSmallestPairs(int[] nums1, int[] nums2, in
2016-07-08 11:03:27 613
2积分系列——经典算法与人工智能在外卖物流调度中的应用
2018-04-26
Outlier Analysis 2nd Edition.pdf ——2积分系列
2018-03-28
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人