数组
明明77
这个作者很懒,什么都没留下…
展开
-
数组
数组是一种数据格式,能够存储多个同类型的值,以为数组可用来实现线性表的顺序存储、哈希表等,二维数组可用来保存图的邻接矩阵等。一维数组的声明与字符数组 1.1一维数组的声明与初始化 1.一维数组的声明 一维数组声明应指出以下三点: 1)存储在每个元素中的值的类型; 2)数组名; 3)数组中的元素数,数组的元素必须用值大于等于1的常量表达式定义。 数组定义中的类型可以是内置数据类型或类类转载 2017-12-13 18:03:17 · 144 阅读 · 0 评论 -
[leetcode]1.Two Sum
题目链接:https://leetcode.com/problems/two-sum/Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers su转载 2017-12-13 18:57:42 · 136 阅读 · 0 评论 -
面试--求数组,左边的数都小于等于它,右边的数都大于等于它
题目在一个 int 数组里查找这样的数,它大于等于左侧所有数,小于等于右侧所有数。直观想法是用两个数组 a、b。a[i]、b[i]分别保存从前到 i 的最大的数和从后到 i 的最小的数,一个解答:这需要两次遍历,然后再遍历一次原数组,将所有 data[i]>=a[i-1]&&data[i]<=b[i]的 data[i]找出即可。给出这个解答后,面试官有要求只能用一个辅助数组,且要求少遍历一次。转载 2017-12-14 19:04:44 · 2662 阅读 · 0 评论 -
面试-剑指offer-数组中出现次数超过一半的数字
题目数组中有一个数字出现的次数超过数组长度的一般,请找出这个数字。思路解法一:基于Partition函数的O(n)算法数组中有一个数字出现的次数超过了数组长度的一般。如果把这个数组排序,那么排序之后位于数组中间的数字一定就是那个出现次数超过数组长度一半的数字。也就是说,这个数字就是统计学上的中位数,即长度为n的数组中第n/2大的数字。我么有成熟的O(n)的算法得到数组中任意第k大的数字。快速排转载 2017-12-14 21:58:21 · 156 阅读 · 0 评论 -
[leetcode] 4. Median of Two Sorted Arrays
题目链接: https://leetcode.com/problems/median-of-two-sorted-arrays/There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run tim转载 2017-12-15 09:48:13 · 109 阅读 · 0 评论 -
[Leetcode] 88.Merge Sorted Array
[leetcode] 88. Merge Sorted Array题目链接:https://leetcode.com/problems/merge-sorted-array/Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume转载 2017-12-25 18:55:59 · 140 阅读 · 0 评论 -
[leetcode] 26. Remove Duplicates from Sorted Array
题目链接:https://leetcode.com/problems/remove-duplicates-from-sorted-array/Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allo转载 2017-12-17 15:14:29 · 124 阅读 · 0 评论 -
[leetcode] 27. Remove Element
题目链接:https://leetcode.com/problems/remove-element/Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn’t matt转载 2017-12-17 15:21:59 · 126 阅读 · 0 评论 -
[leetcode] 35. Search Insert Position
题目链接:https://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 inserte转载 2017-12-18 09:40:26 · 128 阅读 · 0 评论