![](https://img-blog.csdnimg.cn/2019092715111047.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
数组与矩阵
文章平均质量分 64
leetcode数组与矩阵
Destinyf
这个作者很懒,什么都没留下…
展开
-
710. Random Pick with Blacklist 黑名单中的随机数(Hard)
1. 描述给定一个包含 [0,n) 中不重复整数的黑名单 blacklist ,写一个函数从 [0, n) 中返回一个不在 blacklist 中的随机整数。对它进行优化使其尽量少的调用Math.random()。You are given an integer n and an array of unique integers blacklist. Design an algorithm to pick a random integer in the range [0, n - 1] tha原创 2021-08-29 11:06:54 · 153 阅读 · 0 评论 -
380. Insert Delete GetRandom O(1) O(1) 时间插入、删除和获取随机元素(Medium)
1. 描述Implement the RandomizedSet class:RandomizedSet() Initializes the RandomizedSet object.bool insert(int val) Inserts an item val into the set if not present. Returns true if the item was not present, false otherwise.bool remove(int val) Removes a原创 2021-07-25 14:47:37 · 84 阅读 · 0 评论 -
leetcode 283. Move Zeroes(Easy) 移动零
1. 描述Given an integer array nums, move all 0’s to the end of it while maintaining the relative order of the non-zero elements.Note that you must do this in-place without making a copy of the array.给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。2. 分析原创 2021-07-22 10:33:29 · 140 阅读 · 0 评论 -
leetcode 27. Remove Element(Easy) 移除元素
1. 描述Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed.Since it is impossible to change the length of the array in some languages, you must instead have the原创 2021-07-21 18:40:15 · 125 阅读 · 0 评论 -
leetcode 26. Remove Duplicates from Sorted Array(Easy) 删除有序数组中的重复项
1. 描述给你一个有序数组 nums ,请你 原地 删除重复出现的元素,使每个元素 只出现一次 ,返回删除后数组的新长度。不要使用额外的数组空间,你必须在 原地 修改输入数组 并在使用 O(1) 额外空间的条件下完成2. 分析有序数组,首先想到双指针,本题可以采用快慢指针。由于数组有序,相同元素必定相邻,例子中要求的结果是数组的前一部分变更为不重复的元素,故可以用fast指针遍历数组,若fast指向元素与slow指向元素不相等,则将nums[fast]存储到nums[++slow]即可。3.原创 2021-07-21 17:35:13 · 56 阅读 · 0 评论 -
leetcode 344. Reverse String(Easy) 反转字符串
1. DescriptionWrite a function that reverses a string. The input string is given as an array of characters s.编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 char[] 的形式给出。不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。你可以假设数组中的所有字符都是 ASCII 码表中的可打印字符。2. Analysis要原创 2021-07-21 10:50:56 · 71 阅读 · 0 评论 -
leetcode 167. Two Sum II - Input array is sorted(Easy) 两数之和 II - 输入有序数组
1. DescriptionGiven an array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number.Return the indices of the two numbers (1-indexed) as an integer array answer of size 2, w原创 2021-07-19 22:13:02 · 79 阅读 · 0 评论