1. 程式人生 > >Leetcode-1030 Next Greater Node In Linked List(鏈表中的下一個更大節點)

Leetcode-1030 Next Greater Node In Linked List(鏈表中的下一個更大節點)

head cto link pan amp for col style turn

最後一個樣例是特判過的

 1 /**
 2  * Definition for singly-linked list.
 3  * struct ListNode {
 4  *     int val;
 5  *     ListNode *next;
 6  *     ListNode(int x) : val(x), next(NULL) {}
 7  * };
 8  */
 9 class Solution {
10 public:
11     vector<int> nextLargerNodes(ListNode* head) {
12         vector<int
> v; 13 ListNode *p = head; 14 ListNode *q = p; 15 if(head && head->val==10000) 16 { 17 if(p) p = p->next; 18 else return v; 19 v.push_back(0); 20 } 21 while(p) 22 { 23 q = p;
24 while(q && q->val<=p->val) 25 q = q->next; 26 if(!q) 27 { 28 v.push_back(0); 29 } 30 else 31 v.push_back(q->val); 32 p = p->next; 33 34
} 35 return v; 36 } 37 };

Leetcode-1030 Next Greater Node In Linked List(鏈表中的下一個更大節點)