lessfish / leetcode Goto Github PK
View Code? Open in Web Editor NEW【NO LONGER UPDATE】:pencil2: LeetCode solutions with JavaScript
【NO LONGER UPDATE】:pencil2: LeetCode solutions with JavaScript
hi this is my first time to write an issue.
i am from cnblogs 小刺猬001.
that‘s all. thanks for your reading~
wish you have a good mood today.
你好,我之前找工作也是用的js刷的题,大概刷了240多题, 如果有需要我也可以submit我的一些code
很好的repo
对了,我最近也在静心研读underscore~~有机会可以交流交流
我的email:[email protected]
thx
test
The javascript version is exceeding time limit for longer list.
Perhaps you may refer to following java code to develop a javascript version.
public List<List<Integer>> threeSum(int[] nums) {
List<Integer> list;
List<List<Integer>> retList = new LinkedList<>();
Arrays.sort(nums);
for( int i = 0; i < nums.length && nums[i] <= 0; i++){
if( i > 0 && nums[i] == nums[i-1])
continue;
int sum = (-1)*nums[i], front = i + 1, behin = nums.length - 1;
while( front < behin )
if( nums[front] + nums[behin] > sum)
behin--;
else if( nums[front] + nums[behin] < sum)
front++;
else{
list = new LinkedList<Integer>();
list.add(nums[i]);
list.add(nums[front]);
list.add(nums[behin]);
retList.add(list);
while( front<behin && nums[front]==nums[front+1]) front++;
while( front<behin && nums[behin]==nums[behin-1]) behin--;
front++;
behin--;
}
}
return retList;
}
The golang solution using byte to validate the parenthesis hits 0ms compared to ~108ms in javascript.
Maybe we shall try to find a better solution.
func isValid(s string) bool {
if len(s)%2 != 0 {
return false
}
left := map[byte]struct{}{
'(': struct{}{},
'[': struct{}{},
'{': struct{}{},
}
right := map[byte]struct{}{
')': struct{}{},
']': struct{}{},
'}': struct{}{},
}
bytes := []byte(s)
stack := []byte{}
for i := range bytes {
if _, ok := left[bytes[i]]; ok {
stack = append(stack, bytes[i])
} else if _, ok = right[bytes[i]]; ok {
if len(stack) == 0 {
return false
}
switch stack[len(stack)-1] {
case '(':
if bytes[i] != ')' {
return false
}
case '[':
if bytes[i] != ']' {
return false
}
case '{':
if bytes[i] != '}' {
return false
}
}
stack = stack[:len(stack)-1]
} else {
return false
}
}
if len(stack) == 0 {
return true
}
return false
}
你好,从博客园一路逛过来看的。感觉 leetcode 上能拿 js 刷了这么多题的人真不多见😂,我之前也是用 JS, 后来还是随大流用了 Java
主要想问下你 readme.md 是写了什么脚本更新吗?方便就此交流一下吗?
谢谢
$('#problemList tbody tr') 是空
去网站上搜 problemList 也没有。
是leetcode更新了页面dom,还是我打开方式不对 :-(
I think you misunderstand the leetcode description about this problem
That's my test case about this problem, maybe will help you to check your solution
TestCase
看样子就是把链表的每一个数字加起来,如果超过10就取余数,进的一个1就参与到后面2个数的相加里去,最后得出一个新的链表,这样做的意义是什么?哪些实际问题是需要这种算法的?
Currently, it is solved in sequential approach which adds time complexity of O(n) but it can be solved using binary search method which eventually results in better time complexity of O(log n).
Sort List 这题忽略了 using constant space complexity.
链表转数组虽然ac很快,但链表本身失去了意义。
@hanzichi 哈喽,我最近自己也在JS写LeetCode,想要contribute,不知道有没有什么要求呢?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.