2013年10月18日
摘要: Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.Note:Givenm,nsatisfy the following condition:1 ≤m≤n≤ length of list.代码: 1 /** 2 * Definition for singly-linked list. 3 * s 阅读全文
posted @ 2013-10-18 20:55 猿人谷 阅读(447) 评论(0) 推荐(0) 编辑
摘要: [1] Given an array of integers, every element appears twice except for one. Find that single one.[2] Given an array of integers, every element appears three times except for one. Find that single one. (better solution is needed)Note: Your algorithm should have a linear runtime complexity. Could you 阅读全文
posted @ 2013-10-18 20:36 猿人谷 阅读(2445) 评论(1) 推荐(0) 编辑
摘要: 昨晚在参加兰亭集势的笔试时,看到了这样一个题目。大致意思就是给出一个单链表,链表中有重复的元素,需要删除重复的元素。如:1→2→3→5→4→3→7,删除重复元素后变成1→2→3→5→4→7。思路其实还蛮简单:建立三个工作指针p,q,r,然后p遍历全表。p每到一个结点,q就从这个结点往后遍历,并与p的数值比较,相同的话就free掉那个结点。LinkList RemoveDupNode(LinkList L) //删除重复结点的算法{ LinkList p , q , r; p = L -> next; while(p) //p用于遍历链表 { q = p; while(q->next 阅读全文
posted @ 2013-10-18 09:28 猿人谷 阅读(1371) 评论(0) 推荐(0) 编辑