您当前的位置: 首页 >  leetcode

LeetCode Algorithm 1290. 二进制链表转整数

发布时间:2021-12-12 11:14:40 ,浏览量:0

1290. 二进制链表转整数

Ideas

偷了个懒,首先用string类型的str把链表的所有元素都串起来,然后直接用stoi转成int类型,直接AC。

Code C++
#include  class Solution { public: int getDecimalValue(ListNode* head) { string str = ""; while (head) { str += to_string(head->val); head = head->next; } cout << str << endl; return stoi(str, nullptr, 2); } }; 
关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    108697博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0595s