随笔分类 -  LeetCode

摘要:对整数开方 思路:二分法,牛顿迭代法 java: 牛顿迭代法 阅读全文
posted @ 2017-10-11 18:59 wilderness 阅读(109) 评论(0) 推荐(0)
摘要:计算二进制 java: 阅读全文
posted @ 2017-10-11 18:48 wilderness 阅读(139) 评论(0) 推荐(0)
摘要:旋转链表 思路: 把链表连接为一个闭合的环,然后从头计数,到位置剪开 java: 阅读全文
posted @ 2017-10-11 17:38 wilderness 阅读(131) 评论(0) 推荐(0)
摘要:螺旋矩阵 Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example,Given n = 3, You should return the fo 阅读全文
posted @ 2017-10-11 14:29 wilderness 阅读(112) 评论(0) 推荐(0)
摘要:求最后一个单词的长度 Java 1: java 2: Java 3: 阅读全文
posted @ 2017-10-10 17:26 wilderness 阅读(170) 评论(0) 推荐(0)
摘要:这个题在《剑指offer》上面讲过 思路: 1.利用递归 2.遍历,每遍历到一个新的数索引为i,就复制i个新的数组,并且把这个新的数插入新复制出来的数组的各个位置上 java: python: 阅读全文
posted @ 2017-10-10 15:40 wilderness 阅读(173) 评论(0) 推荐(0)
摘要:顺时针旋转图片(矩阵)90度 思路: 转置矩阵+水平旋转180度 java代码: Python代码: 阅读全文
posted @ 2017-10-10 13:35 wilderness 阅读(182) 评论(0) 推荐(0)
摘要:Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums 阅读全文
posted @ 2017-03-14 23:44 wilderness 阅读(186) 评论(0) 推荐(0)
摘要:求一个数组中任意四个数的和为target的所有组合 思路:求n个数的和为target,转变为求n-1个书的和为target-num 阅读全文
posted @ 2017-03-14 22:52 wilderness 阅读(179) 评论(0) 推荐(0)
摘要:计算最少用多少不把word1变为word2, 思路:建立一个dp表,行为word1的长度,宽为word2的长度 1.边界条件,dp[i][0] = i,dp[0][j]=j 2.最优子问题,考虑已经知道word1[0:i-1]转变为word2[0:j-1]的次数,只需要考虑word1[i]和word 阅读全文
posted @ 2017-03-14 10:30 wilderness 阅读(181) 评论(0) 推荐(0)
摘要: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 fo 阅读全文
posted @ 2017-03-13 23:14 wilderness 阅读(123) 评论(0) 推荐(0)
摘要:A message containing letters from A-Z is being encoded to numbers using the following mapping: Given an encoded message containing digits, determine t 阅读全文
posted @ 2017-03-13 14:14 wilderness 阅读(170) 评论(0) 推荐(0)
摘要:一共有n个台阶,每次跳一个或者两个,有多少种走法,典型的Fibonacii问题 还有一种,每次可以跳任意阶,有2^(n-1)种跳法 阅读全文
posted @ 2017-03-12 22:54 wilderness 阅读(134) 评论(0) 推荐(0)
摘要:一个m*n的表格,每个格子有一个非负数,求从左上到右下最短的路径值 和62,63两个值是同一个思路,建立dp表,记录每个位置到右下角的最短路径的值 占用线性空间的解法: 阅读全文
posted @ 2017-03-12 22:26 wilderness 阅读(173) 评论(0) 推荐(0)
摘要:Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space 阅读全文
posted @ 2017-03-12 17:03 wilderness 阅读(206) 评论(0) 推荐(0)
摘要:判断一个物体从左上角到右下角有多少种走法 阅读全文
posted @ 2017-03-12 16:20 wilderness 阅读(116) 评论(0) 推荐(0)
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2, 阅读全文
posted @ 2017-03-12 15:35 wilderness 阅读(173) 评论(0) 推荐(0)
摘要:There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it cost 阅读全文
posted @ 2017-03-10 23:34 wilderness 阅读(183) 评论(0) 推荐(0)
摘要:Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a g 阅读全文
posted @ 2017-03-10 22:32 wilderness 阅读(136) 评论(0) 推荐(0)
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maxim 阅读全文
posted @ 2017-03-10 16:14 wilderness 阅读(156) 评论(0) 推荐(0)