注意构造链表的方式
| 75 | |
| 76 | // 注意构造链表的方式 |
| 77 | ListNode* stringToListNode(string input) { |
| 78 | // Generate list from the input |
| 79 | vector<int> list = stringToIntegerVector(input); |
| 80 | |
| 81 | // Now convert that list into linked list |
| 82 | ListNode* dummyRoot = new ListNode(0); |
| 83 | ListNode* ptr = dummyRoot; |
| 84 | for(int item : list) { |
| 85 | ptr->next = new ListNode(item); |
| 86 | ptr = ptr->next; |
| 87 | } |
| 88 | ptr = dummyRoot->next; |
| 89 | delete dummyRoot; |
| 90 | return ptr; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | // 链表转字符串 |
no test coverage detected