LeetCode 题目总结 本博客不定期更新 LeetCode 题目总结,所有题目使用 Java 实现,小部分题目也提供 JavaScript 代码。我不追求一行 AC 但是我追求一题多解,比较常规的思路,解释清楚复杂度,代码可读性强。欢迎留言和评论,共同进步。这本是我自己用来复习的笔记,如果也能帮到你,那也是我的福报。 如果你想按类型刷题,可以参考我的标签。我做出的分类比 LC 官方的更细一些,比如我有如下展示的这些类型, 2020-03-18 #leetcode
[LeetCode] 二分查找模板 binary search 二分法是算法题里面一个比较基础但是很容易错的概念,一开始练习的时候由于不熟悉二分法的套路,反复出现死循环或者目标值找错,非常影响做题心情。我总结了如下几个模板。原则上这里的模板无论你使用哪一个,都可以解决二分法类型的问题,只不过有一些题目,比如寻找一个最大值/最小值的,可能某一个模板更适合,需要判断的条件较少。 如下模板是用Java实现的 模板一,找有序数组中是否存在一个目标值。注意 r 2021-01-12 #leetcode #java #binary search
[LeetCode] 3206. Alternating Groups I There is a circle of red and blue tiles. You are given an array of integers colors. The color of tile i is represented by colors[i]:colors[i] == 0 means that tile i is red.colors[i] = 2024-11-25 #leetcode #array #java #sliding window
[LeetCode] 1861. Rotating the Box You are given an m x n matrix of characters box representing a side-view of a box. Each cell of the box is one of the following:A stone ‘#’A stationary obstacle ‘*’Empty ‘.’ The box is rotated 90 degr 2024-11-24 #leetcode #array #two pointer #java #matrix
[LeetCode] 3238. Find the Number of Winning Players You are given an integer n representing the number of players in a game and a 2D array pick where pick[i] = [xi, yi] represents that the player x picked a ball of color y. Player i wins the game 2024-11-22 #leetcode #array #hashmap #java #counting sort
[LeetCode] 2257. Count Unguarded Cells in the Grid You are given two integers m and n representing a 0-indexed m x n grid. You are also given two 2D integer arrays guards and walls where guards[i] = [rowi, coli] and walls[j] = [rowj, colj] r 2024-11-21 #leetcode #array #java #matrix #simulation #flood fill
[LeetCode] 2516. Take K of Each Character From Left and Right You are given a string s consisting of the characters ‘a’, ‘b’, and ‘c’ and a non-negative integer k. Each minute, you may take either the leftmost character of s, or the rightmost character of s. Ret 2024-11-20 #leetcode #hashmap #java #sliding window #string
[LeetCode] 1652. Defuse the Bomb You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code of length of n and a key k. To decrypt the code, you must replace every number. All t 2024-11-18 #leetcode #array #java #sliding window
[LeetCode] 661. Image Smoother An image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells (i.e., the average of the nine cel 2024-11-17 #leetcode #array #java #matrix
[LeetCode] 911. Online Election You are given two integer arrays persons and times. In an election, the ith vote was cast for persons[i] at time times[i]. For each query at a time t, find the person that was leading the election at 2024-11-15 #leetcode #array #hashmap #java #binary search #design