- 博客(27)
- 资源 (1)
- 收藏
- 关注
原创 *[Lintcode]加油站
在一条环路上有 N 个加油站,其中第 i 个加油站有汽油gas[i],并且从第_i_个加油站前往第_i_+1个加油站需要消耗汽油cost[i]。你有一辆油箱容量无限大的汽车,现在要从某一个加油站出发绕环路一周,一开始油箱为空。求可环绕环路一周时出发的加油站的编号,若不存在环绕一周的方案,则返回-1。样例现在有4个加油站,汽油量gas[i]=[1, 1, 3, 1
2016-09-26 23:13:23 259
原创 [Lintcode]Generate Parentheses 生成括号
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.Have you met this question in a real interview? YesExampleGiven n = 3, a
2016-09-25 17:34:03 464
原创 *[Lintcode]Flatten Nested List Iterator 摊平嵌套的列表
Given a nested list of integers, implement an iterator to flatten it.Each element is either an integer, or a list -- whose elements may also be integers or other lists.Have you met this questi
2016-09-25 16:48:32 616
原创 *[Lintcode]First Missing Positive 丢失的第一个正整数
Given an unsorted integer array, find the first missing positive integer.Have you met this question in a real interview? YesExampleGiven [1,2,0] return 3,and [3,4,-1,1] ret
2016-09-25 11:50:27 399
原创 [Lintcode]First Bad Version 第一个错误的代码版本
The code base version is an integer start from 1 to n. One day, someone committed a bad version in the code case, so it caused this version and the following versions are all failed in the unit tests.
2016-09-25 10:22:30 403
原创 *[Lintcode]Find the Missing Number
Given an array contains N numbers of 0 .. N, find which number doesn't exist in the array.ExampleGiven N = 3 and the array [0, 1, 3], return 2.两种方法,求和后再与0到N的和做减法。或者用异或。第一种:public
2016-09-23 16:49:43 401
原创 [Lintcode]Find Peak Element 寻找峰值
There is an integer array which has the following features:The numbers in adjacent positions are different.A[0] A[A.length - 1].We define a position P is a peek if:A[P] > A[P-1] && A[P] > A
2016-09-23 14:13:22 285
原创 [Lintcode]Find Minimum in Rotated Sorted Array II
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).ExampleGiven [4,4,5,6,7,0,1,2] return 0.与I的区别是可以有重复值。算法类似,但是l
2016-09-22 17:58:57 164
原创 [Lintcode]Find Minimum in Rotated Sorted Array
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).Find the minimum element.ExampleGiven [4, 5, 6, 7, 0, 1, 2]
2016-09-22 17:26:55 165
原创 *[Lintcode]Fast Power
Calculate the an % b where a, b and n are all 32bit integers.ExampleFor 231 % 3 = 2For 1001000 % 1000 = 01.如果n 为奇数可以转化为 (a^(n/2) * a^(n/2) * a ) %b = ((a^(n/2)%b * a^(n/2)%b)%b * (a)%b)
2016-09-21 17:24:24 305
原创 [Lintcode]Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Example["2", "1", "+", "3",
2016-09-20 22:42:14 184
原创 [Lintcode]Edit Distance
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 word:
2016-09-19 22:48:06 172
原创 **[Lintcode]Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return 2147483647ExampleGiven dividend = 100 and divisor = 9, return 11.不能使用乘除和取模,这时可以考虑使
2016-09-19 10:46:35 261
原创 **[Lintcode]Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none)
2016-09-18 15:34:37 237
原创 **[Lintcode]Digit Counts
ount the number of k's between 0 and n. k can be 0 - 9.Exampleif n = 12, k = 1 in[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]参考http://www.hawstein.com/posts/20.4.html,对每一位统计可能出现k的次数。考虑三种
2016-09-18 10:53:04 529
原创 *[Lintcode]Delete Digits
Given string A representative a positive integer which has N digits, remove any k digits of the number, the remaining digits are arranged according to the original order to become a new positive int
2016-09-14 19:05:13 240
原创 *[Lintcode] Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu
2016-09-11 17:53:42 240
原创 [Lintcode]Count of Smaller Number
Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 10000) and an query list. For each query, give you an integer, return the number of element in the
2016-09-11 15:58:03 252
原创 [Lintcode]Segment Tree Query II
For an array, we can build a SegmentTree for it, each node stores an extra attribute count to denote the number of elements in the the array which value is between interval start and end. (The arr
2016-09-11 14:40:56 292
原创 *[Lintcode]Segment Tree Build II
The structure of Segment Tree is a binary tree which each node has two attributes start and end denote an segment / interval.start and end are both integers, they should be assigned in following
2016-09-11 11:00:19 194
原创 [Lintcode]Segment Tree Build
The structure of Segment Tree is a binary tree which each node has two attributes start and end denote an segment / interval.start and end are both integers, they should be assigned in following
2016-09-11 10:22:56 181
原创 [Lintcode]Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.首先在每一个节点后插入其自身的拷贝节点。拷贝节点的next和
2016-09-06 22:48:40 190
原创 *[Lintcode]Convert Sorted List to Balanced BST
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Have you met this question in a real interview? YesExample
2016-09-05 23:07:18 336
原创 [Lintcode] Continuous Subarray Sum
Given an integer array, find a continuous subarray where the sum of numbers is the biggest. Your code should return the index of the first number and the index of the last number. (If their are dupl
2016-09-04 17:18:26 197
原创 [Lintcode]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)
2016-09-04 15:59:12 174
原创 *[Lintcode]Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.ExampleGiven in-order [1,2,3] and pre-order [2,1,3], return a tree: 2 / \1 3以中序数列为基础,记录中序数列的start,end以及前序
2016-09-04 15:15:21 172
原创 [Lintcode]Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.ExampleGiven inorder [1,2,3] and postorder [1,3,2], return a tree: 2 / \1 3递归算法,从后序数组确定每次遍历的根节点,再从中序数组中找到根
2016-09-04 11:24:36 157
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人