leet code 之 链表问题

原来简洁有逻辑的代码会为javaScrip提交大大性能

在leetcode上遇到下面的题目

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

Example:

Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
Explanation: 342 + 465 = 807.

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/add-two-numbers
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

将下面注释的代码进行简洁的变换,速度立马就提高了。

 运行时间从164变为148,击败了一半的js用户的提交,而没优化之前的只击败22%左右。所以写代码真的需要深入思考

 

 

posted @ 2020-09-28 15:25  半忧夏  阅读(171)  评论(0编辑  收藏  举报