11 2014 档案

Leetcode: Valid Palindrome
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Pana... 阅读全文

posted @ 2014-11-28 16:13 Ryan-Xing 阅读(145) 评论(0) 推荐(0)

Leetcode: Valid Parentheses
摘要:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct ... 阅读全文

posted @ 2014-11-28 15:49 Ryan-Xing 阅读(124) 评论(0) 推荐(0)

Difference Between Vector and Deque in C++
摘要:1) Dequeue can quickly insert or delete both at the front or the end. However, vector can only quickly insert or delete at the end.2) Memory allocatio... 阅读全文

posted @ 2014-11-28 13:47 Ryan-Xing 阅读(128) 评论(0) 推荐(0)

Leetcode: ZigZag Conversion
摘要:The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font fo... 阅读全文

posted @ 2014-11-26 21:53 Ryan-Xing 阅读(119) 评论(0) 推荐(0)

Leetcode: Convert Sorted List to Binary Search Tree
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.分析:我们比较熟悉由一个sorted array生成一个BST,不同的是这里的数据... 阅读全文

posted @ 2014-11-25 20:22 Ryan-Xing 阅读(158) 评论(0) 推荐(0)

Leetcode: Copy List with Random Pointer
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy ... 阅读全文

posted @ 2014-11-25 19:36 Ryan-Xing 阅读(107) 评论(0) 推荐(0)

Leetcode: Insertion Sort List
摘要:Sort a linked list using insertion sort.分析:insertion sort是将当前元素插入到已经排好序的元素的适当位置,时间复杂度为O(n^2)。class Solution {public: ListNode *insertionSortList(Li... 阅读全文

posted @ 2014-11-25 18:51 Ryan-Xing 阅读(125) 评论(0) 推荐(0)

Leetcode: Linked List Cycle II
摘要: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?分析:... 阅读全文

posted @ 2014-11-25 15:05 Ryan-Xing 阅读(117) 评论(0) 推荐(0)

Leetcode: Linked List Cycle
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?分析:如果一个linked list中有环,那么在用一个快指针和一个慢指针遍历该li... 阅读全文

posted @ 2014-11-25 14:14 Ryan-Xing 阅读(128) 评论(0) 推荐(0)

Leetcode: Merge k Sorted Lists
摘要:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.分析:一个很简单的解法是调用k-1次merge two sorted linkedlist,假设每个list... 阅读全文

posted @ 2014-11-24 22:19 Ryan-Xing 阅读(189) 评论(0) 推荐(0)

Leetcode: Merge Two Sorted Lists
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.代码:class ... 阅读全文

posted @ 2014-11-19 20:02 Ryan-Xing 阅读(124) 评论(0) 推荐(0)

Leetcode: Partition List
摘要:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the origi... 阅读全文

posted @ 2014-11-19 19:52 Ryan-Xing 阅读(116) 评论(0) 推荐(0)

Leetcode: Remove Duplicates from Sorted List II
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-... 阅读全文

posted @ 2014-11-17 22:40 Ryan-Xing 阅读(163) 评论(0) 推荐(0)

Leetcode: Remove Nth Node From End of List
摘要:Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After re... 阅读全文

posted @ 2014-11-17 22:07 Ryan-Xing 阅读(135) 评论(0) 推荐(0)

Leetcode: Reorder List
摘要: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 exam... 阅读全文

posted @ 2014-11-17 21:38 Ryan-Xing 阅读(165) 评论(0) 推荐(0)

Leetcode: Reverse Linked List II
摘要: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.No... 阅读全文

posted @ 2014-11-17 13:28 Ryan-Xing 阅读(196) 评论(0) 推荐(0)

Leetcode: Reverse Nodes in k-Group
摘要:Given a linked list, reverse the nodes of a linked listkat a time and return its modified list.If the number of nodes is not a multiple ofkthen left-o... 阅读全文

posted @ 2014-11-17 12:26 Ryan-Xing 阅读(182) 评论(0) 推荐(0)

Rotate List
摘要:Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.分析:此题... 阅读全文

posted @ 2014-11-16 15:59 Ryan-Xing 阅读(203) 评论(0) 推荐(0)

Sort List
摘要:Sort a linked list inO(nlogn) time using constant space complexity.分析:merge sort。class Solution {public: ListNode *sortList(ListNode *head) { ... 阅读全文

posted @ 2014-11-16 15:23 Ryan-Xing 阅读(201) 评论(0) 推荐(0)

Swap Nodes in Pairs
摘要: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 algor... 阅读全文

posted @ 2014-11-16 14:52 Ryan-Xing 阅读(117) 评论(0) 推荐(0)

Add Two Numbers
摘要:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single ... 阅读全文

posted @ 2014-11-16 14:17 Ryan-Xing 阅读(129) 评论(0) 推荐(0)

Remove Duplicates from Sorted List
摘要:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu... 阅读全文

posted @ 2014-11-16 13:51 Ryan-Xing 阅读(127) 评论(0) 推荐(0)