![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数组
我是真不会写代码啊
python是工作,java是生活。
展开
-
3. 560 和为K的子数组(mid)
二、 思路先理解明白题,那意思是要找出来所有的和等于k的个数。先弄个preSum,然后两个for循环挨个的遍历,找到了就ans++。三、标准答案总结无。原创 2022-06-14 23:16:32 · 118 阅读 · 1 评论 -
2. 304 二维区域和检索(mid)
二、 思路和上一题思路相似,在构建一个二维数组preSum(为了方便比给的matrix多一行一列),preSum[i,j]里面放从[0,0]到[i,j]这个矩形的和。然后求两个点的和就直接preSum[row2+1,col2+1] - preSum[row2+1,col1] - preSum[row1,col2+1]+preSum[row1,col1]三、标准答案总结仔细读题宝,看好变量表示啥意思,不能理所当然。...原创 2022-06-13 23:41:35 · 176 阅读 · 0 评论 -
1. 303区域和检索(easy)
二、 思路其实就是再建个数组,存前n项和,然后到时候求区间和的时候,直接数组内对应两个下标一减就ok了。三、标准答案总结其实就是直接在读取数组的时候,顺便一个for循环求出来前n个数字的和,放到一个新数组里,用的时候直接两个一减就完事儿了。.........原创 2022-06-07 23:25:34 · 123 阅读 · 0 评论 -
4. 3 无重复字符的最长子串(mid)
题目:3 无重复字符的最长子串(mid)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(滑动窗口)2.总结一、题目Given a string s, find the length of the longest substring without repeating characters. Example 1:Input: s = "abcabcbb"Output: 3Explanation: The answer is "abc", with the length of原创 2022-05-04 13:48:42 · 232 阅读 · 0 评论 -
3. 438 找到字符串中所有字母异位词(mid)
题目:438 找到字符串中所有字母异位词(mid)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(滑动窗口)2.总结一、题目Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order.An Anagram is a word or phrase formed by rearranging t原创 2022-05-03 22:58:57 · 321 阅读 · 0 评论 -
1. 76 最小覆盖子串(hard)
题目:76 最小覆盖子串(hard)一、题目二、 思路二、自己写的1.代码三、标准答案1.滑动窗口2.总结一、题目Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no s原创 2022-04-25 22:57:19 · 531 阅读 · 0 评论 -
3. 977 有序数组的平方(easy)
题目:977 有序数组的平方(easy)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(左闭右闭)2.总结一、题目Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. Example 1:Input: nums = [-4,-1,0,3,10]Output:原创 2022-04-19 16:49:13 · 62 阅读 · 0 评论 -
2. 344 反转字符串(easy)
题目:344 反转字符串(easy)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(左闭右闭)2.总结一、题目Write a function that reverses a string. The input string is given as an array of characters s.You must do this by modifying the input array in-place with O(1) extra memory. Example 1:原创 2022-04-19 15:51:32 · 48 阅读 · 0 评论 -
1. 167 两数之和II -输入有序数组(mid)
题目:167 两数之和II -输入有序数组(mid)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(左闭右闭)2.总结一、题目Given a 1-indexed 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. Let these two numbers be原创 2022-04-19 15:33:52 · 152 阅读 · 0 评论 -
3. 283 移动零(easy)
题目:704 Binary Search(easy)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(快慢指针)2.总结一、题目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原创 2022-04-18 14:49:51 · 132 阅读 · 0 评论 -
2. 26删除有序数组中的重复项(easy)
题目:26删除有序数组中的重复项(easy)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(快慢指针)2.总结一、题目Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kep原创 2022-04-18 14:16:57 · 59 阅读 · 0 评论 -
1. 27 移除元素(easy)
题目:27 移除元素(easy)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(快慢指针)3.总结一、题目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原创 2022-04-18 14:08:22 · 212 阅读 · 0 评论 -
5. 367 有效的完全平方数(easy)
题目:367 有效的完全平方数(easy)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(左闭右闭)2.方法二(完全平方数肯定是前n个连续奇数的和)3.方法三(牛顿迭代法)4.总结一、题目Given a positive integer num, write a function which returns True if num is a perfect square else False.Follow up: Do not use any built-in library func原创 2022-04-14 14:26:05 · 231 阅读 · 0 评论 -
4. 69 x的平方根(easy)
@[TOC](题目:69 Sqrt(x)(easy))一、题目Given a non-negative integer x, compute and return the square root of x.Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned.Note: You are not allowe原创 2022-04-13 16:40:56 · 72 阅读 · 0 评论 -
3. 34 在排序数组中查找元素的第一个和最后一个位置(mid)
题目:XXX一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(左闭右闭)2.方法二(左闭右开)3.总结题目:XXX一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(左闭右闭)2.方法二(左闭右开)3.总结Binary Search)一、题目Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search tar原创 2022-04-12 14:14:18 · 106 阅读 · 0 评论 -
2. 35 搜索插入位置(easy)
题目:35 搜索插入位置(二分查找)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(左闭右闭)2.方法二(左闭右开)3.总结一、题目Given a sorted array of distinct integers 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原创 2022-04-06 19:33:24 · 936 阅读 · 0 评论 -
1. 704 二分查找(easy)
题目:704 Binary Search(类别二分查找)一、题目二、 思路二、自己写的1.代码三、标准答案一、题目Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.原创 2022-04-06 15:04:48 · 735 阅读 · 0 评论