
Array
文章平均质量分 55
K.Sun
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
在数组中找出四个数字的和等于指定数字(4Sum)
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution原创 2016-10-13 13:44:05 · 3157 阅读 · 0 评论 -
在一个数组中找到三元组,使得三元组内的三个元素加和为0。
这是一道Google面试题目,题目比较容易理解:看例子:Input : arr[] = {0, -1, 2, -3, 1}Output : 0 -1 1 2 -3 1Input : arr[] = {1, -2, 1, 0, 5}Output : 1 -2 1其中一个最简单的想法就是3层循环,对数组进行遍历,找到加和等于0的三个元素,但是这个方法时间复杂度是O(n3)O(n^原创 2017-03-03 11:31:14 · 7363 阅读 · 0 评论 -
Two Sum II - Input array is sorted
题目地址:https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target num原创 2017-02-13 15:48:18 · 238 阅读 · 0 评论 -
在数组中查找出现奇数次的元素
原文地址:Find the Number Occurring Odd Number of Times已知一个整数数组,除了一个元素只出现了奇数次,其他元素均出现偶数次。在O(n)的时间与常量空间范围内找出这个数字。例如 I/P = [1, 2, 3, 2, 3, 1, 3] O/P = 3一个简单地办法就是两层循环。外部循环逐一选择元素,内部循环计数被选择的元素出现的次数。这个方法的实践复杂度是翻译 2017-01-23 16:57:40 · 1577 阅读 · 0 评论 -
Missing Number
题目地址:https://leetcode.com/problems/missing-number/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]原创 2017-01-19 16:35:35 · 329 阅读 · 0 评论 -
Single Number II
题目地址:https://leetcode.com/problems/single-number-ii/Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one.Note: Your algorithm原创 2017-01-19 09:59:26 · 312 阅读 · 0 评论 -
Find Minimum in Rotated Sorted Array
题目地址:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4原创 2017-01-18 14:48:10 · 270 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II
题目地址:https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array nums = [1,1,1原创 2017-01-18 14:28:56 · 314 阅读 · 0 评论 -
找出数组中所有降序尾部子数组的头元素
已知有这么一个数组: {16, 17, 4, 3, 5, 2},那么它的降序尾部子数组有:{17, 4, 3, 5, 2},{5, 2},{2},所以这几个数组的头元素分别是17,5,2。这个问题比较容易理解,首先可以想到的方法就是双重循环遍历:class LeadersInArray { void printLeaders(int arr[], int size) { fo原创 2017-01-18 11:08:48 · 369 阅读 · 0 评论 -
分发巧克力问题
原文地址:Chocolate Distribution Problem已知一个有n个整数的数组,数组中的每个值表示的是一个包裹中巧克力的数量。每个包裹都有一个表示巧克力数量的变量。这里有m个学生,按下面的规定把巧克力包裹分发出去:每个学生都得到一个包裹;给到学生的巧克力包裹含有的最大巧克力数目与最小巧克力数目的的差为最小。例子:输入: arr[] = {7, 3, 2, 4, 9, 12, 5翻译 2017-01-12 19:38:34 · 555 阅读 · 0 评论 -
锯齿转变(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 NA P L S I I原创 2016-10-12 22:44:49 · 727 阅读 · 0 评论 -
获取数组中K个最大元素(k largest(or smallest) elements in an array | added Min Heap method)
原文地址:http://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/Question: Write an efficient program for printing k largest elements in an array. Elements in array can be in any order.翻译 2016-10-13 19:49:59 · 1015 阅读 · 0 评论 -
Product of Array Except Self
题目地址:https://leetcode.com/problems/product-of-array-except-self/#/descriptionGiven an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all th原创 2017-05-17 11:20:54 · 371 阅读 · 0 评论