摘要:
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?Code:class Solution {public: ListNode *detectCycle(ListNode *head) { ListNode *p=head; ListNode *cur=head; while(p){ i... 阅读全文
摘要:
Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algorithm should use only constant space. You maynotmodify the values inthe list, only nodesitself can bechanged.Code:class Solution {pub 阅读全文