随笔分类 -  leetcode刷题总结

上一页 1 ··· 4 5 6 7 8 9 下一页
https://oj.leetcode.com/
摘要: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-05-18 22:58 SunshineAtNoon 阅读(165) 评论(0) 推荐(0) 编辑
摘要:Given two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one letter can be ... 阅读全文
posted @ 2014-05-18 17:44 SunshineAtNoon 阅读(188) 评论(0) 推荐(0) 编辑
摘要: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-05-18 13:12 SunshineAtNoon 阅读(194) 评论(0) 推荐(0) 编辑
摘要:Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest pa... 阅读全文
posted @ 2014-05-16 17:52 SunshineAtNoon 阅读(228) 评论(0) 推荐(0) 编辑
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie... 阅读全文
posted @ 2014-05-16 16:21 SunshineAtNoon 阅读(270) 评论(0) 推荐(0) 编辑
摘要: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-05-16 11:07 SunshineAtNoon 阅读(193) 评论(0) 推荐(0) 编辑
摘要: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-04-29 21:01 SunshineAtNoon 阅读(242) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointe... 阅读全文
posted @ 2014-04-29 17:32 SunshineAtNoon 阅读(138) 评论(0) 推荐(0) 编辑
摘要:Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ],... 阅读全文
posted @ 2014-04-29 10:40 SunshineAtNoon 阅读(153) 评论(0) 推荐(0) 编辑
摘要:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".题解:用栈就行了代码: 1 class Solution {... 阅读全文
posted @ 2014-04-28 16:35 SunshineAtNoon 阅读(146) 评论(0) 推荐(0) 编辑
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl... 阅读全文
posted @ 2014-04-28 16:14 SunshineAtNoon 阅读(152) 评论(0) 推荐(0) 编辑
摘要:The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie... 阅读全文
posted @ 2014-04-28 15:34 SunshineAtNoon 阅读(302) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note:Recursive solution is trivial, could you do it iteratively?解题:果然不能晚上做题,效率好低。看了讨论才学会的解法。设置一个指针next指向当前访问的节点,如果它不为空,就把它压栈,并且下一个访问它的左节点;如果它为空,就从栈顶一定是它的父... 阅读全文
posted @ 2014-04-03 00:16 SunshineAtNoon 阅读(158) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Not... 阅读全文
posted @ 2014-04-02 15:55 SunshineAtNoon 阅读(202) 评论(0) 推荐(0) 编辑
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?解题:开始进入一个误区,跟循环链表搞混了,其实这个环的开头可以不在head这里,例如... 阅读全文
posted @ 2014-04-02 10:37 SunshineAtNoon 阅读(209) 评论(0) 推荐(0) 编辑
摘要:Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 ... 阅读全文
posted @ 2014-04-01 21:20 SunshineAtNoon 阅读(176) 评论(0) 推荐(0) 编辑
摘要: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 a... 阅读全文
posted @ 2014-04-01 17:05 SunshineAtNoon 阅读(217) 评论(0) 推荐(0) 编辑
摘要:Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321解题:设定一个变量sum存放反转后的答案,每次取输入x的最后一位n,并用sum = sum*10+n更新sum。例如题设的数字123,初始sum为0,过程如下:取末尾的3,sum=3,x=12取末尾的2,sum=32,x=1取末尾的1,sum=321,x=0特别注意x一开始就是0的处理,直接返回0就可以了。代码: 1 class Solution { 2 public: 3 int reverse(int x) {... 阅读全文
posted @ 2014-04-01 11:14 SunshineAtNoon 阅读(152) 评论(0) 推荐(0) 编辑
摘要:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an... 阅读全文
posted @ 2014-04-01 10:58 SunshineAtNoon 阅读(183) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文
posted @ 2014-03-31 21:42 SunshineAtNoon 阅读(223) 评论(0) 推荐(0) 编辑

上一页 1 ··· 4 5 6 7 8 9 下一页
点击右上角即可分享
微信分享提示