• 【LeetCode】237. Delete Node in a Linked List 解题报告 (Java&Python&C++)

    时间:2024-04-27 22:21:11

    作者: 负雪明烛id: fuxuemingzhu个人博客:http://fuxuemingzhu.cn/目录题目描述题目大意解题方法设置当前节点的值为下一个日期[LeetCode]题目地址:https://leetcode.com/problems/delete-node-in-a-linked-l...

  • Python | Leetcode Python题解之第51题N皇后-题解:

    时间:2024-04-27 22:17:17

    class Solution: def solveNQueens(self, n: int) -> List[List[str]]: def generateBoard(): board = list() for i in ra...

  • LeetCode Array Easy 283. Move Zeroes

    时间:2024-04-27 22:14:44

    DescriptionGiven an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.Exampl...

  • [LeetCode] 237. Delete Node in a Linked List 解题思路

    时间:2024-04-27 21:44:25

    Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 ->...

  • 【一天一道LeetCode】#237. Delete Node in a Linked List

    时间:2024-04-27 21:39:11

    一天一道LeetCode本系列文章已全部上传至我的github,地址:ZeeCoder‘s Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处(一)题目Write a function to delete a node (except the tail) in a...

  • [LeetCode] 237. Delete Node in a Linked List 删除链表的节点

    时间:2024-04-27 21:39:25

    Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Given linked list -- head = [4,5,1,9], whi...

  • 每日两题 / 234. 回文链表 && 21. 合并两个有序链表(LeetCode热题100)

    时间:2024-04-27 19:49:14

    234. 回文链表 - 力扣(LeetCode) 先创建一个指针指向第一个节点 dfs到最后一个节点,开始与第一个节点进行比较 class Solution {public: ListNode *t; bool dfs(ListNode *cur) { if (cur...

  • leetcode-二叉树的镜像-91

    时间:2024-04-26 17:14:15

    /** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * TreeNode(int x) : val(x), left(nullptr), r...

  • 【链表】Leetcode 两数相加-算法讲解

    时间:2024-04-26 07:36:36

    我们这里设置一个头结点,然后遍历两个链表,使用一个flag记录相加的结果和进位,如果两个链表没有走到最后或者进位不等于0,我们就继续遍历处理进位;如果当前的链表都遍历完成了,判断当前的进位是否>10,然后处理是否需要添加进位结点 /** * Definition for singly-lin...

  • 【Leetcode每日一题】 分治 - 数组中的第K个最大元素(难度⭐⭐)(63)

    时间:2024-04-25 07:33:46

    1. 题目解析 题目链接:数组中的第K个最大元素 这个问题的理解其实相当简单,只需看一下示例,基本就能明白其含义了。 2.算法原理 在快速排序算法中,一种常见的优化策略是将数组划分为三个区间。这种划分方式可以更加精确地定位到目标元素所在的位置,从而加快排序速度。具体地,这三个区间为:[l, lef...

  • Leetcode 第394场周赛 问题和解法-题目

    时间:2024-04-25 07:17:32

    统计特殊字母的数量 I 给你一个字符串word。如果word中同时存在某个字母的小写形式和大写形式,则称这个字母为特殊字母。 返回word中特殊字母的数量。 示例 1: 输入:word = "aaAbcBC"输出:3解释:word 中的特殊字母是 'a'、'b' 和 'c'。 解题思路 创建两个数...

  • Leetcode 76. 最小覆盖子串

    时间:2024-04-25 07:14:53

    心路历程: 这道题一开始以为要用动态规划来解,但是结合题目中需要返回的是最短子串本身而不是长度,因此在对于字符串s建模时至少需要维护i和j两个变量,再加上这道题没有明显的递推。 这道题是滑动窗口双指针经典问题。 a. fast指针的更新规则:向右移动直到窗口包含了所有t中的元素。 b. slow指...

  • 【代码随想录刷题记录】LeetCode367有效的完全平方数-2. 代码

    时间:2024-04-24 22:21:48

    class Solution {public: //左闭右闭 bool isPerfectSquare(int num) { int left = 0; int right = num; while(left <= right) ...

  • 搜索+剪枝,LeetCode 216. 组合总和 III

    时间:2024-04-24 19:24:37

    目录 一、题目 1、题目描述 2、接口描述 python3 cpp 3、原题链接 二、解题报告 1、思路分析 2、复杂度 3、代码详解 python3 cpp 一、题目 1、题目描述 找出所有相加之和为 n 的 k 个数的组合,且满足下列条件: 只使用数字1到9每个数字 最多使用一次 返回...

  • LeetCode算法题-Number of Lines To Write String(Java实现)

    时间:2024-04-24 17:32:03

    这是悦乐书的第319次更新,第340篇原创01 看题和准备今天介绍的是LeetCode算法题中Easy级别的第188题(顺位题号是806)。我们要将给定字符串S的字母从左到右写成行。每行最大宽度为100个单位,如果写一个字母会导致该行的宽度超过100个单位,则会写入下一行。给出一个数组宽度,一个数组...

  • LeetCode算法题-Subdomain Visit Count(Java实现)

    时间:2024-04-24 17:16:57

    这是悦乐书的第320次更新,第341篇原创01 看题和准备今天介绍的是LeetCode算法题中Easy级别的第189题(顺位题号是811)。像“discuss.leetcode.com”这样的网站域名由各种子域组成。在顶级,我们有“com”,在下一级,我们有“leetcode.com”,在最低级别,...

  • LeetCode算法题-Jewels and Stones(Java实现)

    时间:2024-04-24 17:14:19

    这是悦乐书的第313次更新,第334篇原创01 看题和准备今天介绍的是LeetCode算法题中Easy级别的第182题(顺位题号是771)。字符串J代表珠宝,S代表你拥有的石头。S中的每个字符都是你拥有的一种石头。计算S中有多少石头也是珠宝。J中的字符不会重复出现,J和S中的所有字符都是英文字母。字...

  • LeetCode算法题-Count Primes(Java实现)

    时间:2024-04-24 16:49:42

    这是悦乐书的第190次更新,第193篇原创01 看题和准备今天介绍的是LeetCode算法题中Easy级别的第49题(顺位题号是204)。计算小于非负数n的素数的数量。例如:输入:10输出:4说明:有4个素数小于10,它们是2,3,5,7。本次解题使用的开发工具是eclipse,jdk使用的版本是1...

  • (算法)LeetCode刷题

    时间:2024-04-24 16:48:14

    LeetCode 56 合并区别Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].关键就是a[1]>=b[0] 也就是array[i-1][1]>=array[i][0]const merge = array =...

  • 【leetcode】Spiral Matrix(middle)

    时间:2024-04-23 23:18:45

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, ...