摘要: 1. 每一轮,如果有可以删除的(和为0),则删除,并从头开始遍历;如果没有可以删除的,则右移left。 class Solution { public: ListNode* removeZeroSumSublists(ListNode* head) { head=reverseList(head); 阅读全文
posted @ 2020-04-11 16:33 qiujiejie 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 1. 按序放入栈中,如果当前数字比栈中的数字大,则出栈,更新这个数的next greater node。 class Solution { public: vector<int> nextLargerNodes(ListNode* head) { vector<int> vec; stack<pai 阅读全文
posted @ 2020-04-11 10:37 qiujiejie 阅读(218) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int numComponents(ListNode* head, vector<int>& G) { unordered_set<int> s(G.begin(),G.end()); ListNode *node=head; int re=0; w 阅读全文
posted @ 2020-04-10 09:57 qiujiejie 阅读(88) 评论(0) 推荐(0) 编辑
摘要: 1. len/k=a...b,共k个part,每个part有a个节点,余下的b的节点,从第一个节点开始,每个节点多加一个。 class Solution { public: vector<ListNode*> splitListToParts(ListNode* root, int k) { vec 阅读全文
posted @ 2020-04-10 09:35 qiujiejie 阅读(123) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { int len1=0,len2=0; ListNode *node1=l1,*node2=l2; while(node1) { ++len1; 阅读全文
posted @ 2020-04-09 10:53 qiujiejie 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 1. class Solution { public: ListNode* insertionSortList(ListNode* head) { ListNode ln(0);ln.next=head; ListNode *pre=&ln,*cur=head; while(cur) { if(cu 阅读全文
posted @ 2020-04-09 10:11 qiujiejie 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 1. class Solution { public: void reorderList(ListNode* head) { if(!head) return; vector<ListNode*> vec; ListNode* slow=head,*fast=head,*pre=nullptr; w 阅读全文
posted @ 2020-04-08 09:33 qiujiejie 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 1. class Solution { public: TreeNode* sortedListToBST(ListNode* head) { vector<int> vec; while(head) { vec.push_back(head->val); head=head->next; } Tr 阅读全文
posted @ 2020-04-07 22:59 qiujiejie 阅读(99) 评论(0) 推荐(0) 编辑
摘要: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solu 阅读全文
posted @ 2020-04-07 10:42 qiujiejie 阅读(80) 评论(0) 推荐(0) 编辑
摘要: 1. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class S 阅读全文
posted @ 2020-04-02 09:39 qiujiejie 阅读(112) 评论(0) 推荐(0) 编辑