自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(24)
  • 收藏
  • 关注

原创 leetcode之n Sum 问题

题目:给定一个数组,找出其中的n个数,让他们的和是target已经证明这种问题的复杂度的界是N^(n -1)(n > 2) N 是数组的元素数首先2Sum复杂度是NlogN,复杂度是因为排序需要NlogN实际求两个数是的复杂度是O(N),只需要用两个指针遍历一遍即可同理在3,4sum的时候先枚举前 n - 2个,然后对于最后两个数字使用和2Sum一样的方法即可

2016-03-29 11:58:00 520

原创 leetcode之maximal square

题目: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

2016-03-29 11:11:11 198

原创 hihocoder之智力竞赛

题目:小Hi、小Ho还有被小Hi强拉来的小Z,准备组队参加一个智力竞赛。竞赛采用过关制,共计N个关卡。在第i个关卡中,小Hi他们需要获得Ai点分数才能够进入下一关。每一关的分数都是独立计算的,即使在一关当中获得超过需要的分数,也不会对后面的关卡产生影响。小Hi他们可以通过答题获得分数。答对一道题获得S点分数,答错一道题获得T点分数。在所有的N个关卡中,小Hi他们一共有M次答题机会。

2016-03-27 18:34:13 618

原创 leetcode之Repeated DNA Sequences

题目:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DN

2016-03-25 17:04:48 304

原创 leetcode之 coin change

题目:You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount

2016-03-25 16:03:32 269

原创 网易游戏2016研发实习生招聘在线编程题目 推箱子

题目就不贴了因为明天要参加网易游戏研发岗实习生笔试,所以今天看了看去年的题目,虽然当我看到去年研发岗实习生本科生和研究生最终招的人数是1:138的时候很想弃疗并且后悔投错了岗位,不过想了想还是决定认真的准备下,权当练手了。由于现在已经不能在线提交了,所以也不知道自己写的是不是正确的,只是测试了给的样例通过了。代码思路很简单直接模拟就行不过去年这道题的通过率好像只有42%?不

2016-03-17 13:04:31 1281 1

原创 leetcode之sqrt(x)

题目:Implement int sqrt(int x).Compute and return the square root of x.解答:首先看到x是int类型,可知sqrt(x)是有取值范围的,然后在这个范围中进行二分查找即可class Solution {public: int mySqrt(int x) { if(x

2016-03-13 10:20:54 332

原创 leetcode之Additive Number

题目:Additive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent numb

2016-03-12 21:49:40 372

原创 leetcode之Majority Element II

题目:Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.解答:典型的摩尔投票的方法直接在代码中进行注释讲解class Solutio

2016-03-12 21:14:17 264

原创 leetcode之Course Schedule

题目:There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expr

2016-03-12 20:24:09 268

原创 leetcode之 Minimum Height Trees

题目: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 a

2016-03-11 20:07:14 220

原创 leetcode之Minimum Height Trees

题目:For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are ca

2016-03-11 19:51:58 275

原创 leetcode之Gas Station

题目: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 statio

2016-03-10 16:41:40 246

原创 leetcode之Combination Sum II

题目:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in th

2016-03-10 11:17:35 171

原创 leetcode之 Palindrome Partitioning

题目:Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [

2016-03-10 10:34:54 204

原创 leetcode之Pow(x, n)

题目:Implement pow(x, n).解答:class Solution {public: double myPow(double x, int n) { double base = n > 0 ? x : 1 / x; //n可能为负数 double res = 1; while(n != 0) {

2016-03-06 13:42:00 176

原创 leetcode之jump game

题目: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.De

2016-03-06 12:58:42 219

原创 leetcoede之Patching Array

题目:Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements in the

2016-03-04 13:09:37 243

原创 leetcode之 3Sum Closest

题目: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

2016-03-04 11:52:47 259

原创 leetcode之Lowest Common Ancestor of a Binary Search Tree

题目:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defin

2016-03-04 10:01:35 150

原创 leetcode之search for a range

题目: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 n

2016-03-03 21:45:15 167

原创 leetcode之Combination Sum

题目:Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlim

2016-03-03 20:39:35 139

原创 leetcode之Partition List

题目:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes i

2016-03-03 19:51:11 186

原创 leetcode之2sum

题目:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.解答:直接用has

2016-03-03 18:44:19 210

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除