随笔分类 -  leetcode

[Leetcode 543]二叉树的直径Diameter of Binary Tree
摘要:题目 二叉树的直径,即是求树中任意俩点间的最大距离(深度) Given the root of a binary tree, return the length of the diameter of the tree. The diameter of a binary tree is the len 阅读全文
posted @ 2021-11-23 04:24 alau 阅读(38) 评论(0) 推荐(0)
[Leetcode 19]删除链表中倒数第N个元素Remove Nth Node From End of List
摘要:题目 删除链表head中倒数第N个元素 Given the head of a linked list, remove the nth node from the end of the list and return its head. Example 1: Input: head = [1,2,3 阅读全文
posted @ 2021-11-23 01:13 alau 阅读(34) 评论(0) 推荐(0)
[模板]删除重复值leetcode26/27/80/283
摘要:不消耗额外空间的前提下,将数字向前移向。 https://www.bilibili.com/video/BV1Pv4y1Z76N 阅读全文
posted @ 2021-11-22 07:30 alau 阅读(37) 评论(0) 推荐(0)
[Leetcode 152]最大乘积子串Maximum Product Subarray 踩坑
摘要:【题目】 一串int数组中找到乘积最大的子串,子串必须连续,返回成绩ans Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, 阅读全文
posted @ 2021-09-04 17:46 alau 阅读(59) 评论(0) 推荐(0)
[Leetcode 445]正序链表相加Add Two Numbers II
摘要:【题目】 将链表组成的数相加 leetcode2变式,2题是高位在后,现在是高位在前节点 You are given two non-empty linked lists representing two non-negative integers. The most significant dig 阅读全文
posted @ 2021-08-31 17:11 alau 阅读(79) 评论(0) 推荐(0)
[Leetcode 206]反转链表Reverse Linked List
摘要:【题目】 反转链表是之后很多题的基础 把链表12345反转成54321 Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: Input: head = [ 阅读全文
posted @ 2021-08-31 16:51 alau 阅读(31) 评论(0) 推荐(0)
[Leetcode 2]两数相加链表Add Two Numbers
摘要:【题目】 将两个用list存储的数字相加,返回相加后的值 You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, 阅读全文
posted @ 2021-08-31 14:31 alau 阅读(37) 评论(0) 推荐(0)
[Leetcode 44]合并有序列表Merge k Sorted Lists
摘要:【题目】 将两个有序链表合并成一个有序链表 Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the firs 阅读全文
posted @ 2021-08-30 20:40 alau 阅读(40) 评论(0) 推荐(0)
[Leetcode 11]容器中装最多的水Container With Most Water
摘要:【题目】 木桶短板,能装的最多水,由最短的那条决定 Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are dr 阅读全文
posted @ 2021-08-23 23:23 alau 阅读(55) 评论(0) 推荐(0)
[整理]K sum系列问题 N数之和 多指针模板 leetcode15/16/18/167/259/454
摘要:【整体思路】 先Arrays.sort()排序,不然后续指针没法用 对于K数之和,固定K-2个指针(循环),再用两指针一头一尾,根据sum大了小了,调左或调右 4数之和,2固定2移动; 3数之和,1固定2移动; 一定要记得去重,不仅为了减少工作量,也是确保输出结果的唯一 【题目】 leetcode1 阅读全文
posted @ 2021-08-23 22:39 alau 阅读(99) 评论(0) 推荐(0)
[Leetcode 781]森林中的兔子 Rabbits in Forest 巧妙
摘要:【题目】 问每只兔子,有多少只和你颜色相同的(颜色问全了,不一定问道每只兔子),求这片森林中至少有多少只兔子 There is a forest with an unknown number of rabbits. We asked n rabbits "How many rabbits have 阅读全文
posted @ 2021-08-23 19:09 alau 阅读(62) 评论(0) 推荐(0)
[Leetcode 26/27/80/283/977]移除(重复)元素 指针专题整理
摘要:【总结】 参考https://www.bilibili.com/video/BV1Pv4y1Z76N 适用情况:大部分需数组升序 【代码】 27 移除元素 不用管移除后半部分是否为正确答案,所以可直接nums[flag]=nums[i] class Solution { public int rem 阅读全文
posted @ 2021-08-23 16:52 alau 阅读(48) 评论(0) 推荐(0)
[Leetcode 88]合并有序数组Merge Sorted Array 归并排序
摘要:【题目】 合并两个数组,两个数组已分别顺序排好,不能使用额外数组,就存在nums1中 You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, 阅读全文
posted @ 2021-08-23 11:23 alau 阅读(71) 评论(0) 推荐(0)
[Leetcode 44]合并有序列表Merge k Sorted Lists
摘要:【题目】 找到第一个没有重复出现的字母 Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. Example 1: I 阅读全文
posted @ 2021-08-22 22:44 alau 阅读(45) 评论(0) 推荐(0)
[Leetcode 198/213/337]强盗偷家 House Robber 三题DP整理
摘要:【题目1】 此系列有三题,都是强盗偷家不能偷相邻邻居,否则会被发现。问最多能偷多少钱 You are a professional robber planning to rob houses along a street. Each house has a certain amount of mon 阅读全文
posted @ 2021-08-22 13:10 alau 阅读(85) 评论(0) 推荐(0)
[Leetcode 162]爬楼梯最小耗费Min Cost Climbing Stairs**
摘要:【题目】 爬楼梯变式,可以上1/2台阶,每个台阶有cost,求爬上去的最小耗费 You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cos 阅读全文
posted @ 2021-08-22 11:30 alau 阅读(71) 评论(0) 推荐(0)
[Leetcode 102/107]比较
摘要:待 阅读全文
posted @ 2021-08-20 18:58 alau 阅读(20) 评论(0) 推荐(0)
[Leetcode 162]寻找峰值 Find Peak Element**
摘要:【题目】 寻找峰值返回坐标,比左右都大,时间复杂度必须是 O(log n) A peak element is an element that is strictly greater than its neighbors. Given an integer array nums, find a pe 阅读全文
posted @ 2021-08-19 14:58 alau 阅读(64) 评论(0) 推荐(0)
[Leetcode 152]旋转数组中找到最小值Find Minimum in Rotated Sorted Array
摘要:【题目】 说了一堆就是在旋转后的顺序数组中找最小值,时间复杂度必须是 O(log n) Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the 阅读全文
posted @ 2021-08-19 14:17 alau 阅读(53) 评论(0) 推荐(0)
[Leetcode 718]最长重复子数列Maximum Length of Repeated Subarray
摘要:【题目】 两个数组,求他们最长的相同子串长度,数组长度不一定相同 Given two integer arrays nums1 and nums2, return the maximum length of a subarray that appears in both arrays. Exampl 阅读全文
posted @ 2021-08-19 14:02 alau 阅读(61) 评论(0) 推荐(0)