摘要: 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) 编辑
摘要: Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3. 1 public static LinkedListNode RemoveDuplicatesfromSortedList(LinkedListNode head) 2 { 3 if (head == null . 阅读全文
posted @ 2012-10-11 23:46 ETCOW 阅读(208) 评论(0) 推荐(0) 编辑
摘要: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2,2,3]. 1 public static int RemoveDuplicatesfromSortedArrayII(int[] A) 2 { 3 int prev ... 阅读全文
posted @ 2012-10-11 23:41 ETCOW 阅读(235) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.For example,Given input array A = [1,1,2],Your function should return length = 2, and A 阅读全文
posted @ 2012-10-11 23:37 ETCOW 阅读(303) 评论(0) 推荐(0) 编辑
摘要: Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string (not partial).The function prototype should be:bool isMatch(const ch 阅读全文
posted @ 2012-10-10 23:54 ETCOW 阅读(575) 评论(0) 推荐(0) 编辑