随笔分类 -  算法

Euler's Sum of Powers Conjecture
摘要:转帖:Euler's Sum of Powers Conjecture 存不存在四个大于1的整数的五次幂恰好是另一个整数的五次幂? 暴搜:O(n^4) 用dictionary:O(n^3) 阅读全文
posted @ 2018-11-30 15:50 MicN 阅读(298) 评论(0) 推荐(0)
DP tricks and experiences
摘要:【LeetCode】 关于动态规划的经验与技巧。 很多时候多分配一位空间是为了递推的方便,例如前推两位。 辅助数组的索引,用到的可能是 1 — N,或者是 0 — N-1。 具体要看清 f[i] 每一个确定的状态空间到底是怎样的,f[i] 的值能够代表什么。 不必拘泥于多分配一位空间,更不必拘泥于索 阅读全文
posted @ 2017-11-04 22:58 MicN 阅读(126) 评论(0) 推荐(0)
Stack
摘要:【LeetCode】 LeetCode中关于栈的题目其实不算很多,用到的套路也比较单一。 71 Simplify Path。 题目描述: Given an absolute path for a file (Unix-style), simplify it. For example,path = " 阅读全文
posted @ 2017-09-20 22:15 MicN 阅读(172) 评论(0) 推荐(0)
Intervals
摘要:【LeetCode】 区间。LeetCode第56题和57题。 56. Insert Interval 下面这种解法是原地插入的方法,显然比新建一个列表省空间。 57 Merge Intervals 三种解法,三种思路 ,第一种最快。 阅读全文
posted @ 2017-09-06 21:29 MicN 阅读(413) 评论(0) 推荐(0)
Spiral and Zigzag
摘要:【LeetCode】 虽然感觉spiral matrix 两道题和 zigzag conversion 那道题没有太多联系,但是,毕竟都是相当于数学上的找规律题目。 这种优雅的题目就应该用下面这种优雅的代码写法。 054 Spiral Matrix 059 Spiral Matrix II 006 阅读全文
posted @ 2017-09-03 21:00 MicN 阅读(167) 评论(0) 推荐(0)
Substring
摘要:【LeetCode】 LC第30题,Substring with Concatenation of All words。 题目描述: You are given a string, s, and a list of words, words, that are all of the same len 阅读全文
posted @ 2017-09-01 21:04 MicN 阅读(212) 评论(0) 推荐(0)
Reverse Nodes in k-Group
摘要:【LeetCode】 题目描述: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less 阅读全文
posted @ 2017-08-30 22:08 MicN 阅读(146) 评论(0) 推荐(0)
Parentheses
摘要:【LeetCode】 阅读全文
posted @ 2017-08-30 09:07 MicN 阅读(444) 评论(0) 推荐(0)
Palindrome
摘要:【LeetCode】 阅读全文
posted @ 2017-08-28 11:49 MicN 阅读(102) 评论(0) 推荐(0)
Binary Search
摘要:【LeetCode】 The Core of Binary Search 1、分割两半,判断middle处的元素应该归属于left还是right。 2、判断while循环处的left < right能否相等。 3、注意避免死循环的产生。 4、分割时mid是偏左还是偏右。 5、最好能够考虑清楚最后跳出 阅读全文
posted @ 2017-08-28 11:37 MicN 阅读(97) 评论(0) 推荐(0)
Simulation
摘要:LeetCode 阅读全文
posted @ 2017-08-16 23:59 MicN 阅读(211) 评论(0) 推荐(0)
Waters
摘要:LeetCode 阅读全文
posted @ 2017-08-16 23:58 MicN 阅读(185) 评论(0) 推荐(0)
Matching
摘要:LeetCode 阅读全文
posted @ 2017-08-14 19:19 MicN 阅读(127) 评论(0) 推荐(0)
Single List Reversion
摘要:LeetCode 1. 基于头插法的迭代: 2. 就地逆置的简洁迭代(elegant) 3. 递归 阅读全文
posted @ 2017-08-14 19:19 MicN 阅读(133) 评论(0) 推荐(0)
K-sum
摘要:LeetCode。 关于K-sum问题,最低可以降低到O(nk-1)的复杂度,下面这个解法是在Discuss中看到的关于K-sum的一个通用解法: 首先是原题中的4Sum问题: 然后推广到K-sum问题后,还用到了Backtracking,可以说很elegant了: 阅读全文
posted @ 2017-08-14 19:18 MicN 阅读(194) 评论(0) 推荐(0)
Backtracking(一)
摘要:LeetCode中涉及到回溯的题目有通用的解题套路: 46. permutations 这一类回溯题目中的基础中的基础,无重复数字枚举: 47. permutations II 稍微增加了点难度,有重复的数字,采取的技巧其实是相当于对重复的数字人为规定一个顺序 阅读全文
posted @ 2017-08-13 10:59 MicN 阅读(287) 评论(0) 推荐(0)
Android九宫格解锁有多少种姿势
摘要:参考知乎:知乎。 http://www.zhihu.com/question/24905007/answer/29414497 原答案已被作者删除 1 from itertools import * 2 3 impossible = {'13': '2', 4 '46': '5', 5 '79': 阅读全文
posted @ 2017-05-04 00:29 MicN 阅读(225) 评论(0) 推荐(0)
Little Tricks
摘要:一直都计划好好学算法,一直都计划好好看书刷题,却几乎从来没更新过(算法)博客,几乎从来没有花苦功夫学过。 糜烂的四月,最后一天,更新一些自己看到的小 trick 吧,以后一定要多多更新算法博客。 1. 一道小学三年级的数学题: 【题目】:5□5□5□5□5=1每个方框中都可选择填入+-×÷,不能添加 阅读全文
posted @ 2017-04-30 23:09 MicN 阅读(240) 评论(0) 推荐(0)
LeetCode_Bit Manipulation
摘要:231. Power of Two Given an integer, write a function to determine if it is a power of two. 191. Number of 1 Bits Write a function that takes an unsign 阅读全文
posted @ 2016-03-23 21:54 MicN 阅读(355) 评论(0) 推荐(0)