随笔分类 -  algorithm

算法相关
摘要:n个互不相同的自然数,分别是1,2,3...n,组合成数字的集合,有n!中可能,按照从小到大的顺序依次排列并编号为1,2,3,...n!, 给定一个n和序列号k(1<=k<=n!)请求第k个数字的字符串 想到的方法: 1,有办法求得数字组合的下一个,这样求k次,算法复杂度大约是knlgn(我也不确定 阅读全文
posted @ 2018-12-24 20:16 茫茫碧落 阅读(102) 评论(0) 推荐(0)
摘要:给定一个正整数向一个n*n的矩阵中一次按照顺时针螺旋顺序放入1-n^2的数字: 想到的方法:1,事先根据坐标算出该坐标数值 2,按照题目方法顺时针挨个放入即可 我用的方法二: 阅读全文
posted @ 2018-12-24 15:50 茫茫碧落 阅读(141) 评论(0) 推荐(0)
摘要:虽然是hard,但是意外的不是很难和56题相类似 有一堆区间,这些区间相互没有交集,且顺序按照start从小到大排列,现在插入一个新的区间,求合并后的区间列表 将原来的区间分为三种,一种在插入区间之前的,一种和插入区间有交集的,一种在插入区间之后的,分别处理即可 阅读全文
posted @ 2018-12-23 15:08 茫茫碧落 阅读(101) 评论(0) 推荐(0)
摘要:在46的基础上改改就能通过了 https://www.cnblogs.com/mangmangbiluo/p/10154417.html 阅读全文
posted @ 2018-12-21 15:37 茫茫碧落 阅读(86) 评论(0) 推荐(0)
摘要:一个数组,里面的数字各不相同,排列出其所有可能 方法很多,能想出来的有: 1,排列所有可能,每出现一种就加入到数组中 2,假设有n个数字,先排列出前n-1数字的可能情况,再将最后一个数字加入 我用的第二种 再精简一下: 阅读全文
posted @ 2018-12-21 10:41 茫茫碧落 阅读(156) 评论(0) 推荐(0)
摘要:leetcode 44题,题目大意是两个字符串s,p,s是原字符串,p是匹配字符串.匹配字符串中*可以代替任意长度字符串(包括空字符串);?可以视作任意单个字符串,下面是一些示例 采用的方法毫无疑问就是动态规划,(i,j)代表了s前i个字符和p前j个字符是否匹配,我一开始用的是字典: 但是提示说内存 阅读全文
posted @ 2018-12-20 13:49 茫茫碧落 阅读(178) 评论(0) 推荐(0)
摘要:很无聊的一道题目歧义也很多 判断一个字符串是否能够用十进制数表示,下面是一堆范例 "0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => true" -90e3 " => true" 1e" => fals 阅读全文
posted @ 2018-12-18 17:45 茫茫碧落 阅读(130) 评论(0) 推荐(0)
摘要:"""56. Merge IntervalsMedium1483116FavoriteShareGiven a collection of intervals, merge all overlapping intervals. Example 1: Input: [[1,3],[2,6],[8,10 阅读全文
posted @ 2018-12-12 13:08 茫茫碧落 阅读(135) 评论(0) 推荐(0)
摘要:"""42. Trapping Rain WaterHard248947FavoriteShareGiven n non-negative integers representing an elevation map where the width of each bar is 1, compute 阅读全文
posted @ 2018-12-11 14:03 茫茫碧落 阅读(131) 评论(0) 推荐(0)
摘要:"""93. Restore IP AddressesMedium473177 Given a string containing only digits, restore it by returning all possible valid IP address combinations. Exa 阅读全文
posted @ 2018-12-10 10:46 茫茫碧落 阅读(150) 评论(0) 推荐(0)
摘要:"""32. Longest Valid ParenthesesHard134368 Given a string containing just the characters '(' and ')', find the length of the longest valid (well-forme 阅读全文
posted @ 2018-12-09 18:40 茫茫碧落 阅读(124) 评论(0) 推荐(0)
摘要:可以写成O(1)的空间复杂度,当然时间复杂度还是O(N^2)首先回顾一下高中的数学知识,二维坐标系上的一点(m,n)顺时针旋转90度后坐标为(n,-m)矩阵左上角坐标(0,0),右下角坐标(n-1, n-1),x轴向下,y轴向右,和我们平时看到的坐标系只是旋转了一下,所以矩阵顺时针旋转和我们平时遇到 阅读全文
posted @ 2018-12-05 16:24 茫茫碧落 阅读(89) 评论(0) 推荐(0)
摘要:因为是硬件出生,所以相对比较容易 """ 89. Gray Code Medium 267 919 The gray code is a binary numeral system where two successive values differ in only one bit. Given a 阅读全文
posted @ 2018-12-05 11:18 茫茫碧落 阅读(209) 评论(0) 推荐(1)
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). Y 阅读全文
posted @ 2018-12-04 18:05 茫茫碧落 阅读(131) 评论(0) 推荐(0)
摘要:""" You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once a... 阅读全文
posted @ 2018-11-28 15:20 茫茫碧落 阅读(160) 评论(0) 推荐(0)
摘要:Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Example 2: Example 3: Note: -100.0 < x < 100.0 n is a 32-bit signed int 阅读全文
posted @ 2018-11-02 11:45 茫茫碧落 阅读(163) 评论(0) 推荐(0)
摘要:我现在主要学的python,会一点c++,这两个语言可以说是leetcode上面最好做题目的语言了,c++有现成的stl可以用,python由于语言特性的问题自然是很方便; 个人感觉做算法题主要是思路,语言并不重要 用python做题还有一点“好处”,只要算法复杂度不对基本不能通过,其他语言可能还会 阅读全文
posted @ 2018-11-02 11:14 茫茫碧落 阅读(657) 评论(0) 推荐(0)
摘要: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 or 阅读全文
posted @ 2018-11-02 10:52 茫茫碧落 阅读(119) 评论(0) 推荐(0)
摘要:Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Example 1: Example 2: Cla 阅读全文
posted @ 2018-11-02 10:18 茫茫碧落 阅读(118) 评论(0) 推荐(0)
摘要:https://blog.csdn.net/fx677588/article/details/72357389 https://blog.csdn.net/hyqsong/article/details/49429859 前面的两种是递归和非递归的实现,图文并茂,写的很好 后面的方法二和三可以拓展思 阅读全文
posted @ 2018-11-02 09:50 茫茫碧落 阅读(113) 评论(0) 推荐(0)