02 2014 档案

2-28
摘要:今天也只刷了4道题。1.需要注意string不是char*,直接在对应位置赋值最终不会正确返回string2.求区间的题比求位置的题需要多注意一下,返回的位置是靠前还是靠后。 阅读全文

posted @ 2014-02-28 20:01 pengyu2003 阅读(87) 评论(0) 推荐(0)

Unique Paths
摘要:A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).How many possible uni 阅读全文

posted @ 2014-02-28 19:57 pengyu2003 阅读(120) 评论(0) 推荐(0)

Count and Say
摘要:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off as"one 2, thenone 1"or1211.Given an integern, generate thenthsequence.Note: The sequence of inte 阅读全文

posted @ 2014-02-28 16:33 pengyu2003 阅读(144) 评论(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.Note:A valid Sudoku board (partially filled) is not necessarily solvable. Only the f 阅读全文

posted @ 2014-02-28 15:13 pengyu2003 阅读(152) 评论(0) 推荐(0)

Search Insert Position
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here are few examples.[1,3,5,6], 5 → 2[1,3,5,6], 2 → 1[1,3,5,6], 7 → 4[1,3,5,6], 0 → 0注意边界条件class Soluti 阅读全文

posted @ 2014-02-28 14:01 pengyu2003 阅读(154) 评论(0) 推荐(0)

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 removing the second node from the end, the linked list becomes 1->2->3->5.Note:Givennwill always be valid.Try to do this in one pass.各种 阅读全文

posted @ 2014-02-27 21:32 pengyu2003 阅读(136) 评论(0) 推荐(0)

Valid Parentheses
摘要:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct order,"()"and"()[]{}"are all valid but"(]"and"([)]"are not.用栈会 阅读全文

posted @ 2014-02-27 21:30 pengyu2003 阅读(96) 评论(0) 推荐(0)

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.if... else if不要偷懒直接写 if...if.../** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x)... 阅读全文

posted @ 2014-02-27 21:28 pengyu2003 阅读(90) 评论(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 algorithm should use only constant space. You maynotmodify the values in the list, only nodes itself can be changed.代码不是最简的,处理head的部分明显可以 阅读全文

posted @ 2014-02-27 21:26 pengyu2003 阅读(110) 评论(0) 推荐(0)

2-27
摘要:今天刷了4道题。总结:1.==------>=不要笔误2.该if...elseif...的不要只写if...if...可能上个if运行完继续下个if。3.vector随机读很快,但随机删除很慢。定位的时候,如果用迭代器iterator比较麻烦,如果删除vector的第i个元素,不妨直接(vectorobj).erase(obj.begin()+i,obj.begin()+i+1);其中删除的是前面的元素,最后一个元素不删除。欢欢乐乐看书去了~~ 阅读全文

posted @ 2014-02-27 21:23 pengyu2003 阅读(90) 评论(0) 推荐(0)

导航