
LeetCode
子非渔
这个作者很懒,什么都没留下…
展开
-
【LeetCode】
Max Points on a Line Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.原创 2016-12-11 02:01:32 · 1008 阅读 · 0 评论 -
【LeetCode】005.Longest Palindromic Substring - javascript解法
程序应该没有问题,提交不能AC,主要的原因是超时。最好的时候,达到85个案例,还有几个案例未能测试。本地测试未通过案例,均可以。可能是我使用对象而非数组来作为动态规划的容器,导致开销过大。目前结合前面用Javascript刷LeetCode发现,在 javascript 中,乘除操作比较耗时,for循环能少则少。后面还会注意不同操作的耗时、性能情况。原创 2017-08-05 10:55:00 · 591 阅读 · 2 评论 -
【LeetCode】149. Max Points on a Line - javascript
提交效率:192 ms ,55%这一题,出现了 javascript 精度问题。最后的案例 [[0,0],[94911151,94911150],[94911152,94911151]] 是没法通过的。会将会两个点计算为同一个斜率的,造成结果的不对。原创 2017-08-06 10:56:48 · 686 阅读 · 0 评论 -
【LeetCode】007.Reverse Integer - javascript求解
Reverse digits of an integer.方案一:不考虑所谓溢出,因为在 javascript 中没有溢出这个概念,或者说这个概念不是特别强。完全可以用数组,字符串的方式解决。原创 2017-08-06 09:37:14 · 526 阅读 · 0 评论 -
【LeetCode】006.ZigZag Conversion - javascript
ZigZag转换,是什么意思?这个是困扰大家解题的关键。本质就是Z字形转换:将字符串换Z字排好,或者是倒“N”型排好;然后再按行重新组成新的字符串。原创 2017-08-05 22:24:56 · 651 阅读 · 0 评论 -
【LeetCode】150. Evaluate Reverse Polish Notation
提交结果: 102 ms,84% 这题正常思路如下代码所示。需要注意的是负数。可以进一步,将三个函数合成一个原创 2017-08-04 14:30:13 · 334 阅读 · 0 评论 -
【LeetCode】003.Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.照例使用 javascript 编程: 这题乍看不难,实际上,在效率提高方面可以参照 KMP 算法。尽可能的减少重复运算。保留求解域的连续性。提交结果:159 ms ,92%var lengthOfLo原创 2017-08-04 13:38:39 · 284 阅读 · 0 评论 -
【LeetCode】001. Two Sum
正常思路,循环嵌套。用了一些技巧,如 indexOf, map。但对真实效率没有帮助。换用前置数组后,效率能提高一些。原创 2017-08-04 07:43:24 · 505 阅读 · 0 评论 -
【LeetCode】004. Median of Two Sorted Arrays
这题在LeetCode上标记的是Hard,也确实提交了好几次才 AC 的。效率也不高,最终成绩为:229ms , 22.3%。有很多边界条件需要考虑,细节问题应该也可以优化,只是没想到beats 这么低。原创 2017-08-04 12:08:01 · 311 阅读 · 0 评论 -
【LeetCode】002. Add Two Numbers
这一题的话,本质不难。但我使用的JavaScript有点麻烦。首先,在节点的定义上,原题给的就是一个错误的定义,不能使用。修改定义后,发现题目的测试案例又不是用的定义给的,而是用数组代表这个链表。这个跟原题意,使用链表的解法完全不是同一个难度等级。原创 2017-08-04 09:46:45 · 327 阅读 · 0 评论 -
【Leetcode】416-Partition Equal Subset Sum -- javascript解法 01背包问题
Partition Equal Subset Sum的javascript解法原创 2017-06-30 22:27:50 · 900 阅读 · 0 评论 -
【LeetCode】214. Shortest Palindrome
先贴一个C语言版的,没有通过AC。自我感觉良好,没有bug,但是在最后一个测试用例上超出运行时间。等待装好开发环境后,测试一下。char* shortestPalindrome(char* s) { char c; int i = 1; char* length =NULL;char* copyStart = NULL;char* copyEnd =NULL ;char* s原创 2017-02-27 09:53:52 · 961 阅读 · 0 评论 -
【LeetCode】151. Reverse Words in a String
Given an input string, reverse the string word by word. For example, Given s = “the sky is blue”, return “blue is sky the”. Update (2015-02-12): For C programmers: Try to solve it in原创 2017-02-26 19:44:09 · 893 阅读 · 0 评论 -
【Android与Cordova插件】Cordova插件的调试方案
var last = function(n,lORr){ if(n==1){ return 1 }else{ if(lORr){//from left to right if(n%2 === 0){ return 2*last((n/2),false) }else{原创 2017-02-26 19:31:20 · 1454 阅读 · 0 评论 -
【LeetCode】467. Unique Substrings in Wraparound String
leetcode 467. Unique Substrings in Wraparound String的两种算法:用于找出所有的子串。并打印出子串出现的次数。原创 2016-12-16 01:44:25 · 952 阅读 · 1 评论 -
【LeetCode】390. Elimination Game
There is a list of sorted integers from 1 to n. Starting from left to right, remove the first number and every other number afterward until you reach the end of the list.Repeat the previous step again,原创 2016-12-11 11:23:38 · 1286 阅读 · 0 评论 -
【Leetcode】008.String to Integer (atoi) javascript 解法
题目:作一个 aoti 功能的函数。与 C语言 中不同的是不能转换的值为 -1 ,且遇到非数字串即刻停止,返回当前解。– Leetcode-008 举例:num = ' 0123a23' => 123num = ' b12'=> 0思路: 求值为一个渐进过程 求值终止条件为 [^\d+-\s] result = result * 10 + n 代码原创 2018-01-09 22:12:54 · 579 阅读 · 0 评论