自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(38)
  • 收藏
  • 关注

原创 总结一下

总结一下,最近做了一部分leetcode的题目1.通过做题目,熟悉js语法还是蛮好的,熟悉一下以前的算法也是蛮好的2.很多题目是需要通过空间来换时间的。有些题目为了提高效率,需要好好动脑筋,这个动脑筋,希望变成一种习惯,比如如果写排序算法,你是写冒泡还是写插入排序?希望提高程序效率是一种习惯,而不是只是一种做题目的时候的感觉3.遇到复杂的题目,我对自己的要求是先解决,再优化,然

2017-10-31 13:52:27 114

原创 leetcode 47

啧啧啧,我排名98%nums.sort(function (a,b) { return a>b});arrl=[];arr=[];function search(nums){ if(nums.length==0){ arrl.push(arr.slice(0)); return ; } for(var i=0;ilengt

2017-10-30 20:58:54 105

原创 leetcode 46

/** * @param {number[]} nums * @return {number[][]} */var permute = function(nums) { arr=[]; arrl=[]; function search(nums){ if(nums.length==0){ arrl.push(arr.slice

2017-10-30 20:33:02 160

原创 leetcode 231

很水 /** * @param {number} n * @return {boolean} */var isPowerOfTwo = function(n) {    if(n        return false;    }    if(n==1){        return true;    }    while(n>1){     

2017-10-29 13:19:13 198

原创 leetcode 205

/** * @param {string} s * @param {string} t * @return {boolean} */var isIsomorphic = function(s, t) { len_s=s.length; dict1=new Array(); dict2=new Array(); for(var i=0;ilen_s;i++

2017-10-29 12:48:46 168

原创 leetcode 204

第一种方法超时,需要的是ln(n)的空间第二种方法是筛选法,需要n的空间var countPrimes1 = function(n) { //最快的方式是一边找素数一遍数数 arr=[2,3]; p=4; count=2; while(p<n){ flag=0; for(var i=0;iarr.lengt

2017-10-28 16:13:14 116

原创 leetcode 202

呵呵,这个我第一/** * @param {number} n * @return {boolean} */var isHappy = function(n) { function search(n){ sum=0; while(n>0){ sum+=(n % 10)*(n%10);

2017-10-28 15:24:52 104

原创 leetcode 40

能解决问题,但效率不咋地/** * @param {number[]} candidates * @param {number} target * @return {number[][]} */var combinationSum = function(candidates, target) { var arrl=[]; arr=[]; candidates

2017-10-26 17:33:05 230

原创 leetcode 39

多写代码身体好/** * @param {number[]} candidates * @param {number} target * @return {number[][]} */var combinationSum = function(candidates, target) {        var arrl=[];    arr=[];   

2017-10-26 15:49:36 101

原创 leetcode 120

代码还是写的很水/** * @param {number[][]} triangle * @return {number} */var minimumTotal = function(triangle) {    result1=triangle[0].slice(0);    result2=result1.slice(0);    min=triangl

2017-10-25 12:46:28 139

原创 leetcode 119

一如既往的水/** * @param {number} rowIndex * @return {number[]} */var getRow = function(rowIndex) {        numRows=rowIndex+1;    result1=[1];    result2=result1;    if(numRows==0)

2017-10-25 11:26:44 163

原创 leetcode 118

我承认这个代码写的很水/** * @param {number} numRows * @return {number[][]} */var generate = function(numRows) {    result1=[1];    result2=result1;    result=[];    result.push(result1); 

2017-10-25 11:22:53 124

原创 leetcode 52

这个题目我想复杂了,我以为要考虑旋转棋盘后得到的解是重复的,我search了一下,发现不是这个意思,然后稍微改一下代码即可arr_l=[];arr=[];search(0);var count=0;function search(i){ if(i==n){ arr1=[]; for(var i=0;ii++){

2017-10-23 13:20:57 223

原创 leetcode 51

https://leetcode.com/submissions/detail/124893020/83%的成绩,其实程序不难,但很久没写N Queen问题了var solveNQueens = function(n) { arr_l=[]; arr=[]; search(0); function search(i){ if(

2017-10-23 12:57:20 221

原创 leetcode 71

https://leetcode.com/problems/simplify-path/description/第一次拿第一,开心    /**     * @param {string} path     * @return {string}     */    var simplifyPath = function(path) {    arr=pa

2017-10-18 17:46:40 143

原创 leetcode 73

和排名第一的代码差不多,这个题目不难/** * @param {number[][]} matrix * @return {void} Do not return anything, modify matrix in-place instead. */var setZeroes = function(matrix) {    n=matrix.length; 

2017-10-18 16:28:29 167

原创 leetcode 69

这题简单的,用系统函数,这个是我的代码我排名后面的原因是提交次数太多,sad/** * @param {number} x * @return {number} */var mySqrt = function(x) {    return Math.floor(Math.sqrt(x));};

2017-10-18 15:54:05 197

原创 leetcode 90

var subsetsWithDup = function(nums){let res = [[]]; let begin = 0;我的代码效率很低只有30%/** * @param {number[]} nums * @return {number[][]} */var subsetsWithDup = functi

2017-10-17 16:59:48 239

原创 leetcode 93

Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order

2017-10-17 15:53:56 176

原创 leetcoder 78

Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[ [3], [1],

2017-10-16 15:58:39 131

原创 leetcode 77

Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:这个题目非常简单,但我做了2-3个小时,我的思路和排名第一的思路是一致的,这里需要注意js需要深度co

2017-10-16 13:33:30 126

原创 leetcode 64

https://leetcode.com/problems/minimum-path-sum/description/Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbe

2017-10-14 17:09:16 128

原创 leetcode 63

https://leetcode.com/problems/unique-paths-ii/description/Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle

2017-10-14 11:14:16 173

原创 leetcode 62 unique-paths

https://leetcode.com/problems/unique-paths/description/效率不是特别高/** * @param {number} m * @param {number} n * @return {number} */var uniquePaths = function(m, n) {     var re1= n

2017-10-13 17:53:15 137

原创 感受

最近看了js的一些资料我的感受四年前的js和现在大不一样,现在全行业计算机水平和10年前也不一样。很多以前认为比较难的事情,现在相对都比较简单,而且随着需求的不断变化,新的特型被加入。比如编译原理。ecma一直在更新,不知道c这块的更新速度是否和ecma差不多? 新的语言特型被加入到js中,前端到底未来在哪里?nodejs让js变成后端的一种选择,但前端的框架显然比nodejs要热的多。而且前端的

2017-10-13 16:48:58 154

原创 leetcode Add to List 5. Longest Palindromic Substring

Add to List 5. Longest Palindromic Substringhttps://leetcode.com/problems/longest-palindromic-substring/description/说我超时,但我觉得我的代码已比较优化了,不知道系统怎么了/** * @param {string} s * @return

2017-10-13 14:04:37 128

原创 leetcode 48

https://leetcode.com/problems/rotate-image/description/48. Rotate Image这个题目简单的就是需要动动脑子知道矩阵怎么旋转的,这个比较费劲,然后我排名比较后面,有点郁闷第一名是一开始做倒序排列,然后每次交换两个数字就好了/** * @param {number[][]}

2017-10-13 11:14:45 221

原创 leetcode 28

Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Seen this question in a real interview before?   Y

2017-10-13 10:33:03 287

原创 leetcode 27

Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.

2017-10-13 10:09:36 113

原创 emca 262 6.0

开始阅读 http://www.ecma-international.org/ecma-262/6.0/#sec-number-constructor-number-value看看什么时候能看完

2017-10-13 09:27:28 181

原创 leetcode generate-parentheses

https://leetcode.com/problems/generate-parentheses/description/这道题还好,一开始我还怕了一下子,想想就好了,也学会了用webstrom 调试nodejs的方式来调js,否则每次用chrome太麻烦了第一名的代码我也看过了,不用我那么麻烦的判断和额外的数组,这道题还行/** * @param {number} n

2017-10-12 17:52:29 165

原创 leetcode zigzag-convert

https://leetcode.com/problems/zigzag-conversion/description//** * @param {string} s * @param {number} numRows * @return {string} */var convert = function(s, numRows) {var arr=[];

2017-10-12 15:42:26 146

原创 leetcode remove-element

https://leetcode.com/problems/remove-element/description/Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space f

2017-10-12 15:07:03 122

原创 leetcode 回文数

判断回文数的问题https://leetcode.com/problems/palindrome-number/description/Determine whether an integer is a palindrome. Do this without extra space.这里注意负数不要判断javascript证书和浮点数是一个数据类型,所以需要用mat

2017-10-12 12:07:05 238

原创 leetcode题目 1

Given nums = [2, 7, 11, 15], target = 9,Because nums[0] + nums[1] = 2 + 7 = 9,return [0, 1].比较笨的方法,排名比较后面,哈哈哈/** * @param {number[]} nums * @param {number} target * @retur

2017-10-11 13:55:23 96

原创 js题目

罗马数字的题目。首先你需要知道罗马数字是怎么来的。具体我这里不说了我后来搜了一下别的答案,有更加好的,你们自己去搜吧,但是我不太确定他这个思路是对的还有类似于我这样查表的,但我这个表好的点在于,扩展性比较好,比如万,亿等等数字都可以在这里扩展,他们的答案是写死的function convert(num) {var arr=[['I','V','X'],['X','L',

2017-10-11 10:14:46 133

原创 js题目

写一个电话号码匹配555-555-5555(555)555-5555(555)555-5555555555 555555555555551555 555 5555这里我合并了一些,用了两个正则表达式来匹配var reg1=/^[1]{0,1}[\s]{0,1}\d{3}[\s-]*\d{3}[-\s]*\d{4}$/;

2017-10-11 10:12:21 328

原创 小店开张

小店开张

2017-10-11 10:09:56 174

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除