自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(18)
  • 收藏
  • 关注

原创 LeetCode 393 - 编码验证

题目链接https://leetcode-cn.com/problems/utf-8-validation/题目:Given an integer array data representing the data, return whether it is a valid UTF-8 encoding.A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:For a 1-byte c

2022-03-13 20:36:30 7798

原创 LeetCode 41 - 缺失的第一个正数

题目链接https://leetcode-cn.com/problems/first-missing-positive/题目:Given an unsorted integer array nums, return the smallest missing positive integer.You must implement an algorithm that runs in O(n) time and uses constant extra space.Example 1:Inpu

2022-03-13 18:37:12 1203

原创 LeetCode 42 - 接雨水(动态规划)

题目链接https://leetcode-cn.com/problems/trapping-rain-water/submissions/题目:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.Input: height = [0,1,0,2,1,0,1,3,2

2022-03-12 21:07:01 1318

原创 LeetCode 38 - 外观数列

题目链接https://leetcode-cn.com/problems/count-and-say/题目:给定一个正整数 n ,输出外观数列的第 n 项。「外观数列」是一个整数序列,从数字 1 开始,序列中的每一项都是对前一项的描述。你可以将其视作是由递归公式定义的数字字符串序列:countAndSay(1) = "1"countAndSay(n) 是对 countAndSay(n-1) 的描述,然后转换成另一个数字字符串。前五项如下:1. 12. 113....

2022-03-11 19:19:18 66

原创 LeetCode 23 - 合并有序链表(困难链表)

题目链接https://leetcode-cn.com/problems/merge-k-sorted-lists/题目:You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.Merge all the linked-lists into one sorted linked-list and return it.Example 1:Input: lists

2022-03-11 15:47:50 588

原创 LeetCode 27 - 移除元素(简单)

题目链接https://leetcode-cn.com/problems/remove-element/submissions/题目: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 le

2022-03-10 10:08:46 6311

原创 LeetCode 26 - 删除有序数组的重复元素(简单)

题目链接https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/题目: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 sho

2022-03-10 09:58:27 166

原创 LeetCode 18 - 四数之和(双指针法)

题目链接https://leetcode-cn.com/problems/4sum/comments/题目:给你一个由 n 个整数组成的数组nums ,和一个目标值 target 。请你找出并返回满足下述全部条件且不重复的四元组[nums[a], nums[b], nums[c], nums[d]](若两个四元组元素一一对应,则认为两个四元组重复)Given an array nums of n integers, return an array of all the unique...

2022-03-10 09:48:42 393

原创 LeetCode 22 - 括号生成 (简单递归)

题目链接https://leetcode-cn.com/problems/generate-parentheses/submissions/题目:数字n代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且有效的括号组合。Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.Example 1:Input: n = 3O...

2022-03-01 20:12:24 6687

原创 LeetCode 847 - 访问所有节点的最短路径

题目链接https://leetcode-cn.com/problems/shortest-path-visiting-all-nodes/题目:存在一个由 n 个节点组成的无向连通图,图中的节点按从 0 到 n - 1 编号。给你一个数组 graph 表示这个图。其中,graph[i] 是一个列表,由所有与节点 i 直接相连的节点组成。返回能够访问所有节点的最短路径的长度。你可以在任一节点开始和停止,也可以多次重访节点,并且可以重用边。You have an undirected, connect

2022-02-24 11:49:17 521

原创 并查集:模板&例题

简述:并查集(union find)是一种简单高效的数据结构,适用于解决元素分组的问题。并查集提供两种主要的操作:Union(合并两个集合)和Find(查找两个元素是否属于一个集合)。一般我们使用经过路径压缩和按大小合并这两种方式优化的并查集算法。路径压缩指的是对于某个集合当中的所有元素,他们都具有一个共同而且直接的父元素,即这个集合的代表元素,而不需要递归向上搜索。代码实现的方法是:集合每加入一个元素,直接将其父元素设置为原集合的父元素即可(未考虑按大小合并)。按大小合并指的是依照集合的大小决

2022-02-22 00:24:57 273

原创 LeetCode1631 - 最小体力消耗 (二分法BFS遍历、并查集)

题目:You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated(位于) in the top-left cell, (0, 0), and you hope to travel to th

2022-02-21 23:56:38 229

原创 LeetCode778 - 水位上升的泳池 (二分法BFS遍历、并查集)

题目:You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j).The rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to another 4-directionally ad

2022-02-15 18:14:26 227

原创 LeetCode 74 - 搜索二维矩阵 (二分法)

题目:Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is greater than the last inte

2022-02-14 14:25:36 577

原创 LeetCode187 - 重复的DNA (哈希表、哈希集合)

题目:The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'.For example, "ACGAATTCCG" is a DNA sequence.When studying DNA, it is useful to identify repeated sequences within the DNA.Given a string s that represen

2022-02-14 00:20:38 263

原创 LeetCode 162 - 寻找峰值 (二分法)

题目:A peak element is an element that is strictly greater than its neighbors.Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.You may imagine that nums[-

2022-02-13 23:48:18 186

原创 贪心法:LeetCode1218 - 最长定差子序列

题目:Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals difference.A subsequence is a sequ

2022-02-13 19:58:23 366

原创 贪心法:LeetCode561 - 数组拆分(简单)

题目描述:Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum.给定长度为 2n 的整数数组 nums ,你的任务是将这些数分成 n 对, 例如 (a1, b1), (a

2022-02-13 17:30:43 584

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除