Leetcode 1290. 二进制链表转整数

js版

/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @return {number}
 */
  var getDecimalValue = function (head) {
    let p = head;
    let arr = [];
    while (p.next) {
      arr.push(p.val)
      p = p.next;
    }
    arr.push(p.val)
    return parseInt(arr.join(""), 2)
  };
发布了40 篇原创文章 · 获赞 12 · 访问量 860

猜你喜欢

转载自blog.csdn.net/qq_29334605/article/details/105284943