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); } };