2013年11月9日

Best Time to Buy and Sell Stock III

摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).思路:将vector分 阅读全文

posted @ 2013-11-09 23:47 waruzhi 阅读(166) 评论(0) 推荐(0) 编辑

Letter Combinations of a Phone Number

摘要: Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "23"Output: ["ad", "ae", "af", "bd", "be", &q 阅读全文

posted @ 2013-11-09 21:53 waruzhi 阅读(166) 评论(0) 推荐(0) 编辑

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->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3.思路:指针操作代码: 1 ListNode *deleteDuplicates(ListNode *hea 阅读全文

posted @ 2013-11-09 21:33 waruzhi 阅读(162) 评论(0) 推荐(0) 编辑

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.Note:Givenm,nsatisfy the following condition:1 ≤m≤n≤ length of list.思路:用四个指针分别记录第m-1,m, n, n+1个节点,然后把第m到n个节点之间的node的next指向 阅读全文

posted @ 2013-11-09 20:11 waruzhi 阅读(160) 评论(0) 推荐(0) 编辑

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 original relative order of the nodes in each of the two partitions.For example,Given1->4->3->2->5->2andx= 3,return1->2->2->4->3- 阅读全文

posted @ 2013-11-09 17:42 waruzhi 阅读(169) 评论(0) 推荐(0) 编辑

Valid Sudoku

摘要: Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character'.'.A partially filled sudoku which is valid.思路:思路很简单,只要检查每行、每列、每个子区域中没有重复的数字即可。代码: 1 bool isValidSudoku(vector > &board) 阅读全文

posted @ 2013-11-09 13:09 waruzhi 阅读(174) 评论(0) 推荐(0) 编辑

Trapping Rain Water

摘要: Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example,Given[0,1,0,2,1,0,1,3,2,1,2,1], return6.The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of 阅读全文

posted @ 2013-11-09 09:05 waruzhi 阅读(262) 评论(0) 推荐(0) 编辑

导航