
数组
文章平均质量分 53
忧伤的肚腩
华中科技大学计算机专业在读
展开
-
Leetcode 11. Container With Most Water
如何盛最大的水?数组代表高度, 盛的水量V= min( height[left] 、 height[right] ) * 底部的长度= [right- left]双指针解决这个问题, 从左边、右边不断逼近, 逐渐取得最大值,如何进行更新, 不断进行更新逼近,因为决定的是height[left]、height[right],中的最小值, 所以当,对right 和height 采用快速排序中不...原创 2018-10-11 20:39:48 · 294 阅读 · 0 评论 -
225.使用队列来模拟stack
题目解读使用两个队列来模拟stack 的push、pop()、 top(), isEmpty() 这些基础东西面试过程当中也是主要1.push()2.pop()3. top()4. isEmpty()面试的话主要实现上述几个接口就行了注意在java 队列当中是没有top()方法的,只有peek(),poll()在栈stack 当中才有那中top()队列的api 为poll(),...原创 2019-01-21 21:56:38 · 160 阅读 · 0 评论 -
239.最大滑动窗口
滑动窗口当中的最大值暴力解法扫描正个数组,O(n), 每个节点处需要进行扫描k个节点,所有时间复杂度为O(nk),class Solution { public int[] maxSlidingWindow(int[] nums, int k) { if(k>nums.length) return new int[0]; ...原创 2019-01-21 13:19:49 · 254 阅读 · 0 评论 -
54. Spiral Matrix
顺时针打印矩阵主要是通过不断缩小矩阵的范围,抽象出来即可在开始只要每次缩短这个范围即可,主要是后连执行两边后的条件判断public class Solution { public List<Integer> spiralOrder(int[][] matrix) { List<Integer> res = new ArrayList<I...原创 2018-12-30 16:54:25 · 141 阅读 · 0 评论 -
448. Find All Numbers Disappeared in an Array
查找缺失的数据相似的题目查看如下链接的基本情况448 查找缺失的数据442. Find All Duplicates in an Array先解决查找数组当中相同的元素这道题目是442的,如何查找出数组当中出现多次的元素, 这就是桶排序算法数组当中的每个元素大小都是1<<x<<n ,只要注意这两个地方即可桶排序,归位处理遍历一遍, 将没有归位处理的元素进...原创 2018-12-18 15:34:45 · 160 阅读 · 0 评论 -
387. First Unique Character in a String
暴力解法两个循环hashmap + 两个循环public int solution_1(String s){ if(s==null || s.length()==0){ return -1; } Map&lt;Character, Integer&gt; record = new HashMap&lt;&gt;(); ...原创 2018-12-06 10:07:31 · 204 阅读 · 0 评论 -
34. Find First and Last Position of Element in Sorted Array
描述iven an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If the...原创 2018-11-25 16:10:02 · 304 阅读 · 0 评论 -
295. Find Median from Data Stream
题目描述如何求数据流的中位数情况,这个数据流可以随时添加数据,此题要找出数据流的中位数,数据流由无序整数组成,并且数据流是在变化的。数据流顺序是无序的,添加的顺序也是无序,但是求解是中位数的话就要保持有序的状态,所以基本Median is the middle value in an ordered integer list. If the size of the list is even,...原创 2018-11-25 21:28:01 · 182 阅读 · 0 评论 -
81. Search in Rotated Sorted Array II
31 Search in Rotated Sorted Array ll描述不包含相同的元素情况Input: nums = [4,5,6,7,0,1,2], target = 0Output: 4对有序数组进行一定的旋转,进行查找二分查找and双指针这是二分查找的变体,双指针的形式,low = 0, high = length-1;mid 中间分为两个部分形式nums[mid...原创 2018-11-08 20:36:57 · 255 阅读 · 0 评论 -
169. Majority Element
查重数组中出现次数大于n/2的数总体思路情况思路如下情况基础的过程总结Moore算法相同加一票;不同减一票;当票数减少到0为止,重选选定候选人,第一次候选人的票数初始化为1的情况代码基本步骤设置max_index = 0 , count=1, // 表示将第一数表示为选中的结果,表示作为选手的情况从第二个数开始,如果跟前面的最大数一直 nums[max_index], coun...原创 2018-10-14 15:04:34 · 154 阅读 · 0 评论 -
Leetcode 48. Rotate Image
48. Rotate Image对数组进行旋转,顺时针旋转90度的情况,比如下面的该种情况solution_1参考来源分为两步的情况首先是第一步的情况,先交换逆转行的情况,然后再 array[i][j] 和array[j][i] 进行对调即可代码void rotate(vector<vector<int> > &matrix) { rev...原创 2018-10-13 22:57:52 · 113 阅读 · 0 评论 -
有序数组
导读如何查找一个无序数组中的最大第k个数如何查找一个无序数组中的最小第k个数如何查找两个有序数组中的第k大数如何查找两个有序数组的中位数如何在两个有序数组中找到第K的元素参考链接情况example:Input : Array 1 - 2 3 6 7 9Array 2 - 1 4 8 10k = 5Output : 6Explanation: The final s...原创 2018-10-05 21:39:46 · 2020 阅读 · 0 评论 -
59. 螺旋打印情况
i 代表一圈,j 从用来上下左右移动,主要是控制 i 与j 的参数关系就ok了 ,另一个是注意如何初始化从左上角到右上角while(j<n-i-1)从右上角到右下角while(j<n-i-1)从右下角到左下角while(j>i)从左下角到左上角while(j>i)class Solution { public int[][] ...原创 2019-03-24 20:20:18 · 169 阅读 · 0 评论