Leetcode刷题笔记

白天 夜间 首页 下载 阅读记录
  我的书签   添加书签   移除书签

二进制链表转整数

浏览 62 扫码 分享 2023-11-24 19:12:57

    https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/

    1. /**
    2. * Definition for singly-linked list.
    3. * public class ListNode {
    4. * int val;
    5. * ListNode next;
    6. * ListNode(int x) { val = x; }
    7. * }
    8. */
    9. class Solution {
    10. public int getDecimalValue(ListNode head) {
    11. int res = 0;
    12. if(head == null) return res;
    13. ListNode p = head;
    14. while(p != null){
    15. res = res * 2 + p.val;
    16. p = p.next;
    17. }
    18. return res;
    19. }
    20. }

    若有收获,就点个赞吧

    0 人点赞

    上一篇:
    下一篇:
    • 书签
    • 添加书签 移除书签
    • 931560cons
    • 930994cons(1)
    • 翻转字符串里的单词
    • 返回倒数第 k 个节点
    • 删除链表中的节点/链表
    • 二进制链表转整数
    • 机器人的运动范围/BFS/DFS
    暂无相关搜索结果!

      让时间为你证明

      展开/收起文章目录

      分享,让知识传承更久远

      文章二维码

      手机扫一扫,轻松掌上读

      文档下载

      请下载您需要的格式的文档,随时随地,享受汲取知识的乐趣!
      PDF文档 EPUB文档 MOBI文档

      书签列表

        阅读记录

        阅读进度: 0.00% ( 0/0 ) 重置阅读进度

          思维导图备注