随笔分类 -  LeetCode

摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,... 阅读全文
posted @ 2014-10-29 11:44 非著名程序师 阅读(268) 评论(0) 推荐(0)
摘要:You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb... 阅读全文
posted @ 2014-10-29 11:42 非著名程序师 阅读(2815) 评论(0) 推荐(0)
摘要: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 or... 阅读全文
posted @ 2014-10-29 11:35 非著名程序师 阅读(502) 评论(0) 推荐(0)
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, 阅读全文
posted @ 2014-10-28 23:02 非著名程序师 阅读(571) 评论(0) 推荐(0)
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointe... 阅读全文
posted @ 2014-10-21 21:53 非著名程序师 阅读(365) 评论(0) 推荐(0)
摘要:给定一个二叉树,以集合方式返回其中序/先序方式遍历的所有元素。有两种方法,一种是经典的中序/先序方式的经典递归方式,另一种可以结合栈来实现非递归Given a binary tree, return theinordertraversal of its nodes' values.For examp... 阅读全文
posted @ 2014-10-21 21:44 非著名程序师 阅读(572) 评论(0) 推荐(0)
摘要:Given two binarytrees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and... 阅读全文
posted @ 2014-10-21 21:37 非著名程序师 阅读(768) 评论(0) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?注意,链表循环并不是尾指针和头指针相同,可能是在中间某一段形成一个环路,所以不能只判... 阅读全文
posted @ 2014-10-21 21:35 非著名程序师 阅读(1193) 评论(0) 推荐(0)
摘要:Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321本地注意正负号判断比较关键,实现部分可能不是最优的,按照自己的想法实现:设ret = 1;每次对x进行取余mod,然后ret ... 阅读全文
posted @ 2014-10-21 21:31 非著名程序师 阅读(267) 评论(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 lea... 阅读全文
posted @ 2014-10-21 21:25 非著名程序师 阅读(203) 评论(0) 推荐(0)
摘要:Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity... 阅读全文
posted @ 2014-10-21 21:22 非著名程序师 阅读(439) 评论(0) 推荐(0)
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array[2,3,-2,4],the... 阅读全文
posted @ 2014-10-21 21:07 非著名程序师 阅读(232) 评论(0) 推荐(0)