We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
var getDecimalValue = function(head) { // 反转一次链表 let prev = null; let cur = head; while(cur) { [prev, cur.next, cur] = [cur, prev, cur.next] } let i = 0; let sum = 0; while(prev) { if (prev.val) { // 有值的时候进行二进制指数运算 sum += Math.pow(2, i); } prev = prev.next; i++; } return sum; };
The text was updated successfully, but these errors were encountered:
其实从开始遍历到结束也是可以做到的
var getDecimalValue = function(head) { let sum = 0; while(head) { sum = sum * 2 + head.val; head = head.next; } return sum; };
Sorry, something went wrong.
No branches or pull requests
1290. 二进制链表转整数
解题思路
复杂度分析
The text was updated successfully, but these errors were encountered: