摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3.Code:class Solution {public: ListNode *deleteDuplicat 阅读全文
posted @ 2013-11-05 17:47 WinsCoder 阅读(143) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given{1,2,3,4}, reorder it to{1,4,2,3}.Code:class Solution {public: void reorderList(ListNode *head) { if(head==NULL) return; Lis... 阅读全文
posted @ 2013-11-05 17:37 WinsCoder 阅读(195) 评论(0) 推荐(0) 编辑
摘要: Divide two integers without using multiplication, division and mod operator.Code:class Solution {public: int divide(int dividend, int divisor) { int quotient=0; long long d1=abs((long long)dividend); // change to type 64 bits, such as 'long long' or 'double' long long d2=abs(... 阅读全文
posted @ 2013-11-05 07:45 WinsCoder 阅读(134) 评论(0) 推荐(0) 编辑
摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3.Code:class Solution {public: ListNode *reverseKGroup( 阅读全文
posted @ 2013-11-05 04:59 WinsCoder 阅读(140) 评论(0) 推荐(0) 编辑