算法
leoe_
这个作者很懒,什么都没留下…
展开
-
两个栈实现队列
问题:已知下面Stack类以及其三个方法push、pop和count,请用两个stack实现queue类的入队和出队的方法这道题在面试中出现主要考察三点:1、在短时间内,能不能找到这道题足够清晰的思路(思维的敏捷和清晰) 2、能不能在单向表述中,清楚的描述自己的思路和想法(表达能力) 3、对于一些具体的细节能否考虑到大多数人的思路为:入队时:将元素压入s1 出队时:将s1的元素逐个弹出并压入原创 2017-09-26 08:23:33 · 563 阅读 · 0 评论 -
714. Best Time to Buy and Sell Stock with Transaction Fee
Your are given an array of integers prices, for which the i-th element is the price of a given stock on day i; and a non-negative integer fee representing a transaction fee. You may comp...原创 2018-03-06 20:53:34 · 271 阅读 · 0 评论 -
561. Array PartitionI
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large...原创 2018-03-06 22:33:30 · 270 阅读 · 0 评论 -
442.Find All Duplicatesinan Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that appear twice in this array. Could you do it ...原创 2018-03-06 22:39:19 · 314 阅读 · 0 评论 -
169.Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times You may assume that the array is non-empty and the majority element alw...原创 2018-03-06 22:41:25 · 322 阅读 · 0 评论 -
628.Maximum Product Of Three Numbers
Given an integer array, find three numbers whose product is maximum and output the maximum product. Note: The length of the given array will be in range [3,104] and all elements are in t...原创 2018-03-06 22:44:28 · 394 阅读 · 0 评论 -
746.Min Cost Climbing Stairs
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reac...原创 2018-03-06 22:46:21 · 489 阅读 · 0 评论 -
696.Count Binary Substrings
Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0’s and 1’s, and all the 0’s and all the 1’s in these substrings are grouped consecutively....原创 2018-03-06 22:50:25 · 279 阅读 · 0 评论 -
686. Repeated String Match
Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1. For example, with A = “abcd” and B = “c...原创 2018-03-06 22:51:54 · 315 阅读 · 0 评论 -
387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.Note:...原创 2018-03-08 16:40:15 · 298 阅读 · 0 评论 -
20. Valid Parentheses
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. The brackets must close in the correct order, “()” and “()[]{}” are ...原创 2018-03-09 21:46:11 · 286 阅读 · 0 评论 -
238. Product of Array Except Self
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 divisio...原创 2018-03-05 19:57:38 · 319 阅读 · 0 评论 -
769. Max Chunks To Make Sorted
Given an array arr that is a permutation of [0, 1, …, arr.length - 1], we split the array into some number of “chunks” (partitions), and individually sort each chunk. After concatenating the...原创 2018-03-06 19:51:00 · 343 阅读 · 0 评论 -
287. Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate numb原创 2018-01-15 20:44:03 · 336 阅读 · 0 评论 -
字符串转换成整数
题目描述: 输入一个由数字组成的字符串,请把它转换成整数并输出。例如输入“123”则输出123。不能使用库函数atoi。这道题随看着很简单,这里最简单的一个实现的方法为下面所示,这里实现的思路很简单,就是从字符串的最左面开始遍历,每次加上下一个数之前乘以10,表示在当前位数的左边。最后可以得到最后的结果。int StrToInt(const char *str){ ...原创 2017-09-19 10:24:37 · 920 阅读 · 0 评论 -
665. Non-decreasing Array
题目描述:给定一个有n个整数的数组,检查它是否可以通过修改最多一个元素使它变得非递减数组Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.We define an array is non-decreasing i原创 2017-12-20 10:27:07 · 557 阅读 · 0 评论 -
532. K-diff Pairs in an Array
Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers in原创 2017-12-18 14:21:34 · 518 阅读 · 0 评论 -
697. Degree of an Array
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.Your task is to find the smallest possible length of a (co原创 2017-12-16 15:37:08 · 495 阅读 · 0 评论 -
1. Two Sum
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, and you may not use the same ele原创 2017-12-15 17:05:20 · 435 阅读 · 0 评论 -
581. Shortest Unsorted Continuous Subarray
Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.You need to find原创 2018-01-10 18:07:25 · 488 阅读 · 0 评论 -
189. Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as you can, there原创 2017-12-19 16:02:12 · 440 阅读 · 0 评论 -
119. Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?题目描述:求出给定k 行的杨辉三角思原创 2018-01-14 21:10:38 · 282 阅读 · 0 评论 -
53. 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 t原创 2018-01-12 20:47:02 · 276 阅读 · 0 评论 -
35. 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 arra原创 2018-01-15 15:20:05 · 284 阅读 · 0 评论 -
448. Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this ar原创 2018-01-15 16:51:29 · 280 阅读 · 0 评论 -
565. Array Nesting
A zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A[i]], A[A[A[i]]], … } subjected to the rule below. ...原创 2018-03-05 20:46:37 · 244 阅读 · 0 评论