- 博客(99)
- 资源 (2)
- 收藏
- 关注
原创 Best Time to Buy and Sell Stock III - LeetCode 123
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may not
2015-10-10 15:41:09
744
原创 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
491
原创 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
517
原创 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
404
原创 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
430
原创 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
405
原创 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
506
原创 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
433
原创 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
531
原创 Jump Game - LeetCode 55
题目描述:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determin
2015-06-20 20:38:30
492
原创 First Missing Positive - LeetCode 41
题目描述:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses c
2015-06-20 19:12:11
388
原创 Median of Two Sorted Arrays - LeetCode 4
题目描述:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Tags: Divide and Con
2015-06-20 17:42:06
347
原创 Path Sum II - LeetCode 113
题目描述:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5
2015-06-20 11:30:16
377
原创 Sqrt(x) - LeetCode 69
题目描述:Implement int sqrt(int x).Compute and return the square root of x.Hide Tags Math Binary Search分析:类型都是整型,直接二分但是要注意处理非完全平方数。/**///////////////////////8ms//*/class Solution {public:
2015-06-20 09:57:36
328
原创 Search for a Range - LeetCode 34
题目描述:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not fou
2015-06-20 09:55:50
440
原创 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
325
原创 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
435
原创 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
475
原创 Insertion Sort List - LeetCode 147
题目描述:Sort a linked list using insertion sort.Hide Tags Linked List Sort分析:插入排序是在一个已排序的序列中找到当前元素正确的位置,然后插入禁区即可。由于链表不能随机访问,所以每处理一个元素时,都必须从前往后找到正确的位置,然后插入节点即可。为了方便操作,可以新建一个带有头节点的链表new
2015-06-12 22:24:41
496
原创 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
412
原创 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
498
原创 Implement Stack using Queues - LeetCode 225
题目描述:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -
2015-06-11 22:58:39
473
原创 Convert Sorted List to Binary Search Tree - LeetCode 109
题目描述:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Hide Tags Depth-first Search Linked List分析:思路与108题 http://blog.csdn.net/bu_min
2015-06-10 21:07:44
404
原创 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
343
原创 Binary Tree Right Side View - LeetCode 199
题目描述:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree,
2015-06-10 19:26:29
368
转载 g++和gcc的相同点和区别
gcc和g++的区别和联系原文出处:http://blog.csdn.net/nana08/article/details/6910294gcc和g++都是GNU(一个组织)的编译器。1、对于.c后缀的文件,gcc把它当做是C程序;g++当做是C++程序;2、对于.cpp后缀的文件,gcc和g++都会当做c++程序。3、编译阶段,g++会调用gcc;
2015-06-10 17:26:17
357
原创 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
935
原创 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
600
原创 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
原创 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
478
原创 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
513
原创 ubuntu14.04下利用源代码安装配置postgresql
最近在复习数据库基础,于是从头开始整理一些相关知识,为了方便做实验,首先就是在ubuntu14.04上安装postgresql。以下是详细步骤:1、下载最新版的postgresql源码到本地(选择后缀为.tar.gz的),下载地址:http://postgresql.org/ftp/source/2、解压缩 tar zxvf postgresql-9.4.3.tar.gz3、运行
2015-06-05 14:34:20
601
转载 数据库三大范式详解
本文在原文的基础上略作了一些修改。原文出处:http://ce.sysu.edu.cn/cdbm/news/coures/200908/news_20090807210925_242.html数据库范式1NF 2NF 3NF BCNF(实例) 设计范式(范式,数据库设计范式,数据库的设计范式)是符合某一种级别的关系模式的集合。构造数据库必须遵循一定的规则。在关系数据库中,这种规则
2015-06-05 09:49:11
384
原创 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
369
原创 Reorder List - LeetCode 143
题目描述:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder
2015-06-03 21:26:22
359
原创 Triangle - LeetCode 120
题目描述:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4
2015-06-03 18:18:53
365
原创 Contains Duplicate III - LeetCode 220
题目描述:Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i a
2015-06-01 22:44:30
602
原创 Contains Duplicate II - LeetCode 219
题目描述:Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most
2015-06-01 22:40:35
351
原创 Evaluate Reverse Polish Notation - LeetCode 150
题目描述:Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1
2015-05-28 22:50:03
320
原创 ZigZag Conversion - LeetCode 6
题目描述: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 for better legibility)P A H NA P
2015-05-28 21:31:44
353
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人