链表转字符串
| 93 | |
| 94 | // 链表转字符串 |
| 95 | string listNodeToString(ListNode* node) { |
| 96 | if (node == nullptr) { |
| 97 | return "[]"; |
| 98 | } |
| 99 | |
| 100 | string result; |
| 101 | while (node) { |
| 102 | result += to_string(node->val) + ", "; |
| 103 | node = node->next; |
| 104 | } |
| 105 | return "[" + result.substr(0, result.length() - 2) + "]"; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | int main() { |