`
huntfor
  • 浏览: 195703 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论
文章列表
新博文地址:[leetcode]Search Insert Position http://oj.leetcode.com/problems/search-insert-position/   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 order. You may assume no duplicates in the array. H ...
新博文地址:[leetcode]Unique Binary Search Trees http://oj.leetcode.com/problems/unique-binary-search-trees/ 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 ...
新博文:[leetcode]Best Time to Buy and Sell Stock II http://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/   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 as many transactions as ...
新博文地址:[leetcode]Maximum Subarray http://oj.leetcode.com/problems/maximum-subarray/ 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,−5,4],the contiguous subarray [4,−1,2,1] has the largest sum = ...
新博文:[leetcode]Jump Game II  http://oj.leetcode.com/problems/jump-game-ii/ 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. Your goal is to reach the l ...
新博文地址:[leetcode]Jump Game http://oj.leetcode.com/problems/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. Determine if you are able to reach the las ...
新博文地址:[leetcode]Reverse Linked List II http://oj.leetcode.com/problems/reverse-linked-list-ii/ 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, ...
新博文地址:[leetcode]Longest Common Prefix http://oj.leetcode.com/problems/longest-common-prefix/ Write a function to find the longest common prefix string amongst an array of strings.  其实木有必要求出数组最短字符串的长度的,加一个判断即可 public String longestCommonPrefix(String[] strs){ if(strs == null || strs.length == ...
新博文地址:[leetcode]Container With Most Water http://oj.leetcode.com/problems/container-with-most-water/ Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find ...
新博文地址:[leetcode]Linked List Cycle http://oj.leetcode.com/problems/linked-list-cycle/   这道题是很经典的面试题,在腾讯阿里笔试,网易面试中都遇到过原题。。。。双指针,不多说了 Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space?   public boolean hasCycle(ListNode head) { ...
新博文地址:[leetcode]Sqrt(x) http://oj.leetcode.com/problems/sqrtx/   Implement int sqrt(int x). Compute and return the square root of x. 初看这道题目的时候,想的太简单了,以为参数是int类型,返回值是int类型,就直接用了时间复杂度为O(n)的做法,从 x/2 开始往后遍历,知道找出满足 i * i == x的数,并返回。   后来勉强想到了二分查找,但是因为int类型发生的数组越界问题,好一顿纠结。最后看了别人的算法,看到了最合口味的牛顿迭代法: ...
新博文地址:[leetcode]Climbing Stairs http://oj.leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?  是不是很熟悉?跟青蛙上台阶一样一样滴。。。菲波那切数列,不罗嗦 两种方法: 1. 递归(大量 ...
新博文地址:[leetcode]Best Time to Buy and Sell Stock 这道题在2014年蘑菇街实习生招聘笔试中出现过,当时木有做出来。。。而且好多人都木有做出来。。。。现在看来逻辑还是很简单的,简单的一维DP,DP哎。。(╯‵□′)╯︵┻━┻ Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy on ...
oj.leetcode.com/problems/integer-to-roman/   nteger to Roman Total Accepted: 7321 Total Submissions: 22682 Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.  在转换之前先要了解一下罗马数字的相关限制: 写道 在 ...
新博文地址:[leetcode]ZigZag Conversion http://oj.leetcode.com/problems/zigzag-conversion/ 写道 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     N A  ...
Global site tag (gtag.js) - Google Analytics