
OJ
文章平均质量分 71
bu_min
这个作者很懒,什么都没留下…
展开
-
Isomorphic Strings - LeetCode 205
题目描述:Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with a原创 2015-05-19 22:59:03 · 387 阅读 · 0 评论 -
Minimum Path Sum - LeetCode 64
题目描述:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or r原创 2015-05-13 21:33:23 · 352 阅读 · 0 评论 -
Maximum Product Subarray - LeetCode 152
题目描述: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 contiguous subarray [2,3] has the lar原创 2015-05-27 08:24:24 · 389 阅读 · 0 评论 -
Unique Paths II - LeetCode 63
题目描述: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 is marked as 1 and 0 respectivel原创 2015-05-07 21:04:05 · 318 阅读 · 0 评论 -
Search in Rotated Sorted Array - LeetCode 33
题目描述:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array re原创 2015-06-27 11:25:45 · 422 阅读 · 0 评论 -
3Sum Closest - LeetCode 16
题目描述:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would hav原创 2015-06-28 11:32:40 · 404 阅读 · 0 评论 -
House Robber II - LeetCode 213
题目描述:Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. Th原创 2015-05-26 08:42:26 · 350 阅读 · 0 评论 -
Subsets - LeetCode 78
题目描述:Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For exa原创 2015-06-07 22:59:24 · 474 阅读 · 0 评论 -
Two Sum - LeetCode 1
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where原创 2015-05-23 23:21:31 · 329 阅读 · 0 评论 -
Pow(x, n) - LeetCode 50
题目描述:Implement pow(x, n).Hide Tags Math Binary Search分析:C++库中有pow(double x,int y),但是只针对指数为非负的。因此本题只需特殊考虑参数为负数的情况。方法一:1. 当指数为0时,幂为1;2. 当指数为正数时,结果为pow();3. 当指数为负数时,结果为pow()的倒数备注:在考虑第原创 2015-05-24 15:57:24 · 670 阅读 · 0 评论 -
Unique Paths - LeetCode 62
题目描述:A robot is located at the top-left corner of a m x n grid (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 r原创 2015-05-07 20:14:41 · 299 阅读 · 0 评论 -
House Robber - LeetCode 198
题目描述:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjac原创 2015-04-24 22:07:02 · 454 阅读 · 0 评论 -
2015笔试上机题--求员工就餐最大享受度
已知某公司有n个食堂,第i个食堂有m[i]种食物(1(注意,该员工有个挑食的特点,同一种食物他最多点一份。)现告诉你所有食堂食物的信息,希望你进行选择搭配,使得该员工获得最大享受度,并输出这个享受度的值。Input第一行是一个正整数T(1对于每组数据——第一行是三个数n,bot,top,n 代表食堂数目,n属于[1,10],bot和top分别是是这次原创 2015-04-24 21:46:01 · 478 阅读 · 0 评论 -
Edit Distance - LeetCode 72
题目描述:Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a原创 2015-06-03 22:42:29 · 365 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node - LeetCode 116
题目描述:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; };Populate each next pointer to point to its next rig原创 2015-05-22 21:00:31 · 341 阅读 · 0 评论 -
Unique Binary Search Trees - LeetCode 96
题目描述:Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2原创 2015-05-23 19:52:28 · 311 阅读 · 0 评论 -
Convert Sorted Array to Binary Search Tree - LeetCode 108
题目描述:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.Hide Tags Tree Depth-first Search分析:要构造平衡的二叉搜索树(AVL),必须满足平衡条件:它是一棵空树或它的左右两个子树的高度差的绝对值不超过原创 2015-05-23 21:55:13 · 329 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node II - LeetCode 117
题目描述:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use consta原创 2015-05-23 20:54:34 · 361 阅读 · 0 评论 -
Maximal Square - LeetCode 221
题目描述:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0原创 2015-06-05 21:15:38 · 511 阅读 · 0 评论 -
Generate Parentheses - LeetCode 22
题目描述:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())"原创 2015-05-23 20:32:45 · 381 阅读 · 0 评论 -
Summary Ranges - LeetCode 228
题目描述:Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].Credits:Special thanks to @jianchao.li.fight原创 2015-06-28 09:11:16 · 500 阅读 · 0 评论 -
Basic Calculator II - LeetCode 227
题目描述:Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division sho原创 2015-06-27 11:24:33 · 528 阅读 · 0 评论 -
String to Integer (atoi) - LeetCode 8
题目描述:Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible inp原创 2015-05-24 17:18:10 · 367 阅读 · 0 评论 -
Minimum Size Subarray Sum - LeetCode 209
题目描述:Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [原创 2015-05-24 20:52:33 · 331 阅读 · 0 评论 -
Sum Root to Leaf Numbers - LeetCode 129
题目描述:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tot原创 2015-06-13 22:10:40 · 433 阅读 · 0 评论 -
Insertion Sort List - LeetCode 147
题目描述:Sort a linked list using insertion sort.Hide Tags Linked List Sort分析:插入排序是在一个已排序的序列中找到当前元素正确的位置,然后插入禁区即可。由于链表不能随机访问,所以每处理一个元素时,都必须从前往后找到正确的位置,然后插入节点即可。为了方便操作,可以新建一个带有头节点的链表new原创 2015-06-12 22:24:41 · 494 阅读 · 0 评论 -
Invert Binary Tree - LeetCode 226
题目描述:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this origi原创 2015-06-12 20:15:35 · 494 阅读 · 0 评论 -
Bitwise AND of Numbers Range - LeetCode 201
题目描述:Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.Credits:Special thanks to @amrsaqr for adding this problem and creating all test cases.Hide Tag原创 2015-06-12 21:04:54 · 410 阅读 · 0 评论 -
Flatten Binary Tree to Linked List - LeetCode 114
题目描述:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like:原创 2015-06-15 20:29:11 · 322 阅读 · 0 评论 -
Missing Number - LetcCode 268
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm should ru原创 2015-10-05 15:56:14 · 511 阅读 · 0 评论 -
Gas Station - LeetCode 134
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to it原创 2015-10-03 22:53:10 · 428 阅读 · 0 评论 -
Product of Array Except Self - LeetCode 238
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n原创 2015-10-04 23:08:05 · 401 阅读 · 0 评论 -
Perfect Squares - LeetCode 279
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n =原创 2015-10-05 16:41:13 · 486 阅读 · 0 评论 -
Sort List - LeetCode 148
题目描述 :Sort a linked list in O(n log n) time using constant space complexity.Hide Tags Linked List Sort分析:上一题是用插入排序,时间复杂度是O(N^2),这一题要求的时间复杂度只能是快排,归并,或堆。对于数组来讲,这三个算法都是比较容易实现,但是对于链表,快排不太适合,因为每次只将原创 2015-06-13 21:02:33 · 473 阅读 · 0 评论 -
Combinations - LeetCode 77
题目描述:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,原创 2015-06-10 20:13:40 · 336 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II - LeetCode 80
题目描述:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the f原创 2015-05-24 22:47:15 · 367 阅读 · 0 评论 -
Rectangle Area - LeetCode 223
题目描述:Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Rectangle AreaA原创 2015-06-08 22:04:07 · 419 阅读 · 0 评论 -
Count Complete Tree Nodes - LeetCode 222
题目描述:Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely原创 2015-06-08 22:43:10 · 593 阅读 · 0 评论 -
Basic Calculator - LeetCode 224
题目描述:Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and原创 2015-06-09 22:43:48 · 931 阅读 · 0 评论 -
Reverse Linked List II - LeetCode 92
题目描述:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisf原创 2015-05-24 22:14:05 · 271 阅读 · 0 评论