随笔分类 -  leetcode刷题总结

https://oj.leetcode.com/
摘要:Given a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not co... 阅读全文
posted @ 2014-07-21 13:01 SunshineAtNoon 阅读(213) 评论(0) 推荐(0) 编辑
摘要: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 ... 阅读全文
posted @ 2014-07-21 11:52 SunshineAtNoon 阅读(1485) 评论(0) 推荐(0) 编辑
摘要:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space i... 阅读全文
posted @ 2014-07-21 11:13 SunshineAtNoon 阅读(184) 评论(0) 推荐(0) 编辑
摘要:Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to... 阅读全文
posted @ 2014-07-21 10:57 SunshineAtNoon 阅读(138) 评论(0) 推荐(0) 编辑
摘要: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 re... 阅读全文
posted @ 2014-07-20 17:44 SunshineAtNoon 阅读(136) 评论(0) 推荐(0) 编辑
摘要:Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below and ... 阅读全文
posted @ 2014-07-20 17:21 SunshineAtNoon 阅读(189) 评论(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-07-20 16:53 SunshineAtNoon 阅读(222) 评论(0) 推荐(0) 编辑
摘要:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single ... 阅读全文
posted @ 2014-07-20 16:15 SunshineAtNoon 阅读(181) 评论(0) 推荐(0) 编辑
摘要:The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font fo... 阅读全文
posted @ 2014-07-20 15:59 SunshineAtNoon 阅读(321) 评论(0) 推荐(0) 编辑
摘要:Implement pow(x,n).题解:注意两点:普通的递归把n降为n-1会超时,要用二分的方法,每次把xn= x[n/2]* x[n/2] * xn-[n/2]*2, [n/2]表示n除以2下取整。n有可能取负数,负数的时候,先计算pow(x,-n),然后返回1/pow(x,-n);代码如下:... 阅读全文
posted @ 2014-07-20 14:03 SunshineAtNoon 阅读(169) 评论(0) 推荐(0) 编辑
摘要:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at... 阅读全文
posted @ 2014-07-20 13:48 SunshineAtNoon 阅读(280) 评论(0) 推荐(0) 编辑
摘要:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.题解:转换的方法:从左往右扫描罗马字符,如果当前的字符对应的数字比上一个数字小,就直接加... 阅读全文
posted @ 2014-07-20 12:29 SunshineAtNoon 阅读(176) 评论(0) 推荐(0) 编辑
摘要:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.题解:基本的罗马字符和数字对应如下表所示:罗马字符数字I1V5X10L50C100D50... 阅读全文
posted @ 2014-07-20 12:01 SunshineAtNoon 阅读(264) 评论(0) 推荐(0) 编辑
摘要:What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extra space.For example,Given ... 阅读全文
posted @ 2014-07-20 11:39 SunshineAtNoon 阅读(235) 评论(0) 推荐(0) 编辑
摘要:Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should ru... 阅读全文
posted @ 2014-07-19 17:52 SunshineAtNoon 阅读(165) 评论(0) 推荐(0) 编辑
摘要:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct ... 阅读全文
posted @ 2014-07-19 17:09 SunshineAtNoon 阅读(141) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n... 阅读全文
posted @ 2014-07-19 16:42 SunshineAtNoon 阅读(341) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and al... 阅读全文
posted @ 2014-07-19 16:25 SunshineAtNoon 阅读(180) 评论(0) 推荐(0) 编辑
摘要:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.类似http://www.cn... 阅读全文
posted @ 2014-07-19 15:26 SunshineAtNoon 阅读(273) 评论(0) 推荐(0) 编辑
摘要:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.题解:如下图所示的一棵树: ... 阅读全文
posted @ 2014-07-19 14:38 SunshineAtNoon 阅读(249) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示