
LeetCode
文章平均质量分 75
记录Leetcode算法题目及解题方法
wq_0708
这个作者很懒,什么都没留下…
展开
-
Leetcode #83:删除排序链表中的重复元素
Leetcode #83:删除排序链表中的重复元素题干示例题解PythonJava题干该问题删除排序链表中的重复元素 题面:Given a sorted linked list, delete all duplicates such that each element appear only once.给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。示例示例 1:输入: 1->1->2输出: 1->2示例 2:输入: 1->1->2原创 2021-11-21 12:26:48 · 118 阅读 · 1 评论 -
Leetcode #310:最小高度树
Leetcode #310:最小高度树题目题干示例示例 1:示例2:示例3:示例4:题解PythonC++题目题干该问题最小高度树 题面:A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree.Given a tree of n n原创 2021-10-17 14:51:25 · 426 阅读 · 0 评论 -
Leetcode #311:稀疏矩阵乘法
Leetcode #311:稀疏矩阵乘法题目题干示例题解C++Python题目题干该问题稀疏矩阵乘法 题面:Given two sparse matrices A and B, return the result of AB.给你两个 稀疏矩阵 A 和 B,请你返回 AB 的结果。你可以默认 A 的列数等于 B 的行数。示例输入:A = [[1,0,0],[-1,0,3]]B = [[7,0,0],[0,0,0],[0,0,1]]输出:[[7,0,0], [-7,0,3]]原创 2021-09-21 17:20:49 · 592 阅读 · 0 评论 -
Leetcode #312:戳气球
Leetcode #312:戳气球题目题干示例题解C++Python题目题干该问题戳气球 题面:You are given n balloons, indexed from 0 to n - 1 . Each balloon is painted with a number on it represented by an array nums. You are asked to burst all the balloons.If you burst the ith balloon, you w原创 2021-09-21 00:02:56 · 249 阅读 · 0 评论 -
Leetcode #313: 超级丑数
Leetcode #313: 超级丑数题目题干示例题解PythonC++题目题干该问题超级丑数 题面:A super ugly number is a positive integer whose prime factors are in the array primes. Given an integer n and an array of integers primes, return the nth super ugly number. The nth super ugly number原创 2021-09-12 15:15:44 · 148 阅读 · 0 评论 -
Leetcode #314:二叉树的竖直遍历
Leetcode #314:二叉树的竖直遍历题目题干示例题解C++题目题干该问题二叉树的竖直遍历 题面:Given a binary tree, return the vertical order traversal of its nodes’ values. (ie, from top to bottom, column by column).If two nodes are in the same row and column, the order should be from left原创 2021-09-03 20:40:06 · 455 阅读 · 0 评论 -
Leetcode #315: 计算右侧小于当前元素的个数
Leetcode #315: 计算右侧小于当前元素的个数题目题干示例题解方法一:蛮力法。PythonC++方法二:使用容器。PythonC++方法三: 构建二叉搜索树。C++题目题干该问题计算右侧小于当前元素的个数 题面:You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the num原创 2021-09-02 20:25:18 · 343 阅读 · 0 评论 -
Leetcode #316:去除重复字母
Leetcode #316:去除重复字母题目题干示例题解JavaPython题目题干该问题去除重复字母Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.给你一个字符串原创 2021-08-06 00:12:23 · 164 阅读 · 0 评论 -
Leetcode #317:离建筑物最近的距离
Leetcode #317:离建筑物最近的距离题目题干示例题解PythonC++题目题干该问题离建筑物最近的距离 题面:You want to build a house on an empty land which reaches all buildings in the shortest amount of distance. You can only move up, down, left and right. You are given a 2D grid of values 0, 1原创 2021-08-31 20:52:47 · 1108 阅读 · 0 评论 -
Leetcode #318: 最大单词长度乘积
Leetcode #318:最大单词长度乘积题目题干示例题解解法一PythonC++解法二C++题目题干该问题最大单词长度乘积 题面:Given a string array words, return the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. If no such two words exist, return 0.给定一个字原创 2021-08-28 19:08:18 · 179 阅读 · 0 评论 -
Leetcode #319: 灯泡开关
Leetcode #319:灯泡开关题目题干示例题解解法一Python解法二Python题目题干该问题灯泡 题面:There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb.On the third round, you toggle every third bulb (turning on if it’s off or turnin原创 2021-08-08 15:06:07 · 438 阅读 · 0 评论 -
Leetcode #321:拼接最大数
Leetcode #321:拼接最大数题目题干示例题解Python题目题干问题:拼接最大数You are given two integer arrays nums1 and nums2 of lengths m and n respectively. nums1 and nums2 represent the digits of two numbers. You are also given an integer k.Create the maximum number of length k原创 2021-08-03 23:34:08 · 321 阅读 · 0 评论 -
Leetcode #322:零钱兑换
Leetcode #322:零钱兑换题目题干示例题解JavaPython题目题干看题面:零钱兑换You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.Return the fewest number of coins that you need to make up t原创 2021-07-26 14:53:57 · 179 阅读 · 0 评论 -
Leetcode #323:无向图中连通分量数(并查集)
Leetcode #323:无向图中连通分量数(并查集)题目题干示例题解C++Python题目题干该问题 无向图中连通分量数,看题面:无向图中连通分量数Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to find the number of connected components in an undire原创 2021-07-26 11:34:16 · 1175 阅读 · 0 评论 -
Leetcode #324:摆动排序Ⅱ
Leetcode #324:摆动排序Ⅱ题目题干示例题解题目题干该问题 摆动排序Ⅱ,看题面:摆动排序ⅡGiven an integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]…You may assume the input array always has a valid answer.给你一个整数数组 nums,将它重新排列成 nums[0] < nums[1]原创 2021-07-18 18:50:11 · 142 阅读 · 0 评论 -
Leetcode #325:和等于 k 的最长子数组长度
Leetcode #325:和等于 k 的最长子数组长度题目题干示例题解暴力破解哈希表题目题干该问题 和等于 k 的最长子数组长度,题面:和等于k的最长子数组长度Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn‘t one, return 0 instead.Note:The sum of the entire nums ar原创 2021-07-18 16:08:26 · 728 阅读 · 0 评论 -
Leetcode #326:3的幂
Leetcode #326:3的幂题目题干示例示例 1:示例 2:示例 3:示例 4:题解解法1:循环C++Python解法2:递归C++Python解法3:范化C++Python题目题干该问题3的幂 题面:Given an integer n, return true if it is a power of three. Otherwise, return false.An integer n is a power of three, if there exists an integer x原创 2021-10-24 17:16:00 · 368 阅读 · 0 评论 -
Leetcode #328:奇偶链表
Leetcode #328:奇偶链表题干示例题解Python题干该问题奇偶链表 题面:Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list.The first node is considered odd, and the second n原创 2021-11-21 11:15:17 · 115 阅读 · 0 评论