• LeetCode 中等题解(3)

    时间:2022-12-02 00:36:57

    34 在排序数组中查找元素的第一个和最后一个位置Question给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。你的算法时间复杂度必须是 O(log n) 级别。如果数组中不存在目标值,返回 [-1, -1]。示例 1:输入: num...

  • LeetCode 中等题解(1)

    时间:2022-12-02 00:36:51

    16 最接近的三数之和Question给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。例如,给定数组 nums = [-1,2,1,-4], 和 target =...

  • [LeetCode]题解(python):024-Swap Nodes in Pairs

    时间:2022-11-27 04:44:54

    题目来源:https://leetcode.com/problems/swap-nodes-in-pairs/题意分析:给定一个链表,每两个相邻节点就行交换。比如1->2->3->4,得到2->1->4->3。要求不能改变节点的值,不能新建链表。题目思路:这题是考...

  • 【题解】【字符串】【Leetcode】Valid Palindrome

    时间:2022-11-22 16:26:44

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Pana...

  • LeetCode 题解之Rotate List

    时间:2022-11-16 09:42:35

    1、题目描述 2、题目分析 首先数出链表中的元素个数count,然后对k = k % count 求余数。接着将链表形成一个环,从最后一个元素开始,运动 count - k  步,此时节点的下一个节点就是结果的头节点。 3、代码 1 ListNode* rotateRight(ListNod...

  • [LeetCode]题解(python):020-Valid Parentheses

    时间:2022-11-03 12:11:06

    题目来源:https://leetcode.com/problems/valid-parentheses/题意分析:这道题输入一段只包括括号的字符串,判断这个字符串是否已经配对。配对的规则是,每个'(' 和一个 ')'配对,每个'[' 和一个 ']'配对,每个'{' 和一个 '}' 配对,左括号先出...

  • [LeetCode]题解(python):116 Populating Next Right Pointers in Each Node

    时间:2022-11-01 00:11:25

    题目来源https://leetcode.com/problems/populating-next-right-pointers-in-each-node/Given a binary tree struct TreeLinkNode { TreeLinkNode *left; ...

  • [LeetCode]题解(python):118 Pascal's Triangle

    时间:2022-10-26 07:35:50

    题目来源https://leetcode.com/problems/pascals-triangle/Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Retur...

  • 【LeetCode题解】排序

    时间:2022-10-14 21:39:43

    1. 排序排序(sort)是一种常见的算法,把数据根据特定的顺序进行排列。经典的排序算法如下:冒泡排序(bubble sort)插入排序(insertion sort)选择排序(selection sort)快速排序(quick sort)堆排序(heap sort)归并排序(merge sort)...

  • [LeetCode]题解(python):107 Binary Tree Level Order Traversal II

    时间:2022-10-08 11:19:02

    题目来源https://leetcode.com/problems/binary-tree-level-order-traversal-ii/Given a binary tree, return the bottom-up level order traversal of its nodes' v...

  • 【LeetCode题解】530_二分搜索树的最小绝对值差

    时间:2022-10-05 22:25:46

    【LeetCode题解】530_二分搜索树的最小绝对值差目录【LeetCode题解】530_二分搜索树的最小绝对值差描述方法一、中序遍历二分搜索树思路Java 代码Python 代码描述给定一个所有节点为非负值的二叉搜索树,求树中任意两节点的差的绝对值的最小值。示例 :输入: 1 \ ...

  • Leetcode题解(八)

    时间:2022-09-30 20:41:14

    26、Remove Duplicates from Sorted Array题目直接上代码,方法很简单:class Solution {public: int removeDuplicates(vector<int>& nums) { const int si...

  • Leetcode 题解系列(九)

    时间:2022-09-18 21:44:25

    72. Edit Distance 题目要求 Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is co...

  • [LeetCode]题解(python):030-Substring with Concatenation of All Words

    时间:2022-09-15 18:58:07

    题目来源https://leetcode.com/problems/substring-with-concatenation-of-all-words/You are given a string, s, and a list of words, words, that are all of the...

  • [LeetCode 题解]: Validate Binary Search Tree

    时间:2022-09-12 23:53:37

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only...

  • Leetcode题解---Regular Expression Matching Java实现

    时间:2022-09-01 20:47:34

    leetcode regular expression matching题目链接:https://leetcode.com/problems/regular-expression-matching/#/description 解题思路: (1)匹配串长度为1时,特殊处理  (2)匹配串长度大于1时...

  • [LeetCode]题解(python):044-Wildcard Matching

    时间:2022-09-01 20:47:46

    题目来源: https://leetcode.com/problems/wildcard-matching/   题意分析: 定义两个新字符规则,'?'代表任意一个字符,’*‘代表任意长度的任意字符。输入一个s和p,判断s是否能被p匹配。   题目思路: 这题和前面的一个正则表达式类似,不过比前面那...

  • [LeetCode]题解(python):055-Jump Game

    时间:2022-09-01 15:40:39

    题目来源: https://leetcode.com/problems/jump-game/   题意分析: 输入一个非负数组,数字代表这个位置最多可以跳多少步。判断能否从起始位置跳到最后的位置。比如[2,3,1,1,4]返回True,而[3,2,1,0,4]则返回False。   题目思路: 从其...

  • LeetCode222 Count CompleteTree Nodes(计算全然二叉树的节点数) Java 题解

    时间:2022-08-30 13:34:41

    题目:Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, ...

  • [LeetCode] Trapping Rain Water II 题解

    时间:2022-08-27 15:41:03

    题意题目思路我一开始想的时候只考虑到一个结点周围的边界的情况,并没有考虑到边界的高度其实影响到所有的结点盛水的高度。我们可以发现,中间是否能够盛水取决于边界是否足够高于里面的高度,所以这必然是一个从外到内,从小到大的一个过程。因为优先队列必然首先访问的是边界中最小的高度,如果周围小于这个高度那么必然...