摘要: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.You may not alter the values in the nodes, only nodes itself may be changed.Only constant memory is all 阅读全文
posted @ 2012-10-12 23:57 ETCOW 阅读(222) 评论(0) 推荐(0) 编辑
摘要: Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the following condition:1 ≤ m ≤ n ≤ length of list.REMEBER: 有关列表的题目要注意处理涉及到head Node的情况 1 阅读全文
posted @ 2012-10-12 22:34 ETCOW 阅读(415) 评论(0) 推荐(0) 编辑
摘要: Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Discuss: 1.If the integer's last digit is 0, what should the output be? ie, cases such as 10, 100. 2.Reversed integer overflow. 1 public static int ReverseInteger(int x) 2 { 3 bool... 阅读全文
posted @ 2012-10-12 22:05 ETCOW 阅读(470) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, remove the nth node from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list becomes 1->2->3->5.Note:Given n will always be valid.Try to do this in one pass. 阅读全文
posted @ 2012-10-12 21:55 ETCOW 阅读(206) 评论(0) 推荐(0) 编辑
摘要: Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length. 1 public static int RemoveElemtn(int[] A, int n, int elem) 2 { 3 for (int i = 0;... 阅读全文
posted @ 2012-10-12 21:40 ETCOW 阅读(384) 评论(0) 推荐(0) 编辑
摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1->1->2->3, return 2->3. 1 public static LinkedListNode RemoveDuplicate 阅读全文
posted @ 2012-10-12 00:41 ETCOW 阅读(241) 评论(0) 推荐(0) 编辑