2014年2月27日

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 阅读(130) 评论(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 阅读(86) 评论(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 阅读(81) 评论(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 阅读(94) 评论(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 阅读(83) 评论(0) 推荐(0) 编辑

导航