ICode9

精准搜索请尝试: 精确搜索
  • LeetCode — 最小路径和2022-08-29 06:01:36

    LeetCode — 最小路径和 问题陈述 给定一个 mxn网格 用非负数填充,找到一条从左上角到右下角的路径,该路径最小化沿其路径的所有数字的总和。 笔记: 您只能在任何时间点向下或向右移动。 问题陈述取自: https://leetcode.com/problems/minimum-path-sum 示例 1: Source: LeetCode 输

  • LeetCode 854. K-Similar Strings2022-08-29 05:30:44

    原题链接在这里:https://leetcode.com/problems/k-similar-strings/ 题目: Strings s1 and s2 are k-similar (for some non-negative integer k) if we can swap the positions of two letters in s1 exactly k times so that the resulting string equals s2. Given t

  • leetcode刷题记录之25(集合实现)2022-08-28 23:01:39

    题目描述: 给你链表的头节点 head ,每 k 个节点一组进行翻转,请你返回修改后的链表。 k 是一个正整数,它的值小于或等于链表的长度。如果节点总数不是 k 的整数倍,那么请将最后剩余的节点保持原有顺序。 你不能只是单纯的改变节点内部的值,而是需要实际进行节点交换。   官方题解

  • leetcode-793. 阶乘函数后 K 个零2022-08-28 15:34:46

    793. 阶乘函数后 K 个零 图床:blogimg/刷题记录/leetcode/793/ 刷题代码汇总:https://www.cnblogs.com/geaming/p/16428234.html 题目 思路 首先我们令\(zeta(x)\)为\(x!\)末尾零的个数。根据172.阶乘后的零有\(zeta(x)=\sum_{k=1}^\infty\left\lfloor\frac{x}{5^k}\right\rfloor\)

  • LeetCode 859. Buddy Strings2022-08-28 15:30:41

    原题链接在这里:https://leetcode.com/problems/buddy-strings/ 题目: Given two strings s and goal, return true if you can swap two letters in s so the result is equal to goal, otherwise, return false. Swapping letters is defined as taking two indices i 

  • leetcode-172. 阶乘后的零2022-08-28 12:00:08

    172. 阶乘后的零 图床:blogimg/刷题记录/leetcode/172/ 刷题代码汇总:https://www.cnblogs.com/geaming/p/16428234.html 题目 思路 n!中有几个0与[1,n]中出现多少个5的因数有关。例如7! = 1×2×3×4×5×6×7出现了1次5,故最后末尾会出现1个0。26!中出现了5,10,15,20,25其中5的个

  • LeetCode 1166. Design File System2022-08-28 09:32:57

    原题链接在这里:https://leetcode.com/problems/design-file-system/ 题目: You are asked to design a file system that allows you to create new paths and associate them with different values. The format of a path is one or more concatenated strings of the form: /

  • LeetCode/阶乘后的零2022-08-28 01:03:14

    1. 返回尾零数量 可以转换为求质因子为2和5数量的较小值,实际上就是求质因子为5的数量 class Solution { public: int trailingZeroes(int n) { int ans = 0; for (int i = 5; i <= n; i += 5) //遍历所有含质因子5的数 for (int x = i; x % 5 ==

  • 【重要】LeetCode 662. 二叉树最大宽度2022-08-28 00:33:38

    题目链接 注意事项 根据满二叉树的节点编号规则:若根节点编号为 u,则其左子节点编号为 u << 1,其右节点编号为 u << 1 | 1。 一个朴素的想法是:我们在 DFS过程中使用两个哈希表分别记录每层深度中的最小节点编号和最大节点编号,两者距离即是当前层的宽度,最终所有层数中的最大宽度即是答

  • leetcode-数组中两元素的最大乘积2022-08-26 10:31:13

    题目描述 给你一个整数数组 nums,请你选择数组的两个不同下标 i 和 j,使 (nums[i]-1)*(nums[j]-1) 取得最大值。 请你计算并返回该式的最大值。 示例 1: 输入:nums = [3,4,5,2] 输出:12 解释:如果选择下标 i=1 和 j=2(下标从 0 开始),则可以获得最大值,(nums[1]-1)*(nums[2]-1) = (4-1)*(5-

  • [Leetcode Weekly Contest]3072022-08-24 23:33:20

    链接:LeetCode [Leetcode]2383. 赢得比赛需要的最少训练时长 你正在参加一场比赛,给你两个 正 整数 initialEnergy 和 initialExperience 分别表示你的初始精力和初始经验。 另给你两个下标从 0 开始的整数数组 energy 和 experience,长度均为 n 。 你将会 依次 对上 n 个对手。第 i

  • LeetCode - 三数之和2022-08-23 11:04:55

    题目信息 源地址:三数之和 给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0,请你找出所有和为 0 且不重复的三元组。 注意:答案中不可以包含重复的三元组。 提示信息 示例 1 输入:nums = [-1,0,1,2,-1,-4] 输出:[[-1,-1,2],[-1,0,1]] 示例 2 输

  • LeetCode/变为棋盘2022-08-23 08:32:10

    一个 n x n 的二维网络 board 仅由 0 和 1 组成 。每次移动,你能任意交换两列或是两行的位置 返回将这个矩阵变为  “棋盘”  所需的最小移动次数 ,如果不存在可行的变换,输出 -1 1. 数学方法 移动使满足条件的题目,首先得判断棋盘是否满足条件 容易从棋盘得知,需要满足以

  • LeetCode 367. 有效的完全平方数2022-08-22 19:02:06

    LeetCode 367. 有效的完全平方数 思路: 核心为最后一步判断当二分结束后值为及接近一个整数的浮点数(如2.9xxxx)此时加上极小数(1e-6)取整再平方,若与num相等则为完全平方数 class Solution { public: bool isPerfectSquare(int num) { if (num == 0) return true;

  • LeetCode 34. 在排序数组中查找元素的第一个和最后一个位置2022-08-22 18:31:31

    34. 在排序数组中查找元素的第一个和最后一个位置 思路: 与AcWing 789一致 class Solution { public: vector<int> searchRange(vector<int>& nums, int target) { if (nums.size() == 0) return {-1, -1}; int begin, end; int l = 0, r = nums.size(

  • LeetCode 811. Subdomain Visit Count2022-08-22 03:30:46

    原题链接在这里:https://leetcode.com/problems/subdomain-visit-count/ 题目: A website domain "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com" and at the lo

  • LeetCode/最大二叉树2022-08-20 01:31:22

    给定一个不重复的整数数组 nums 。 最大二叉树 可以用下面的算法从 nums 递归地构建: 创建一个根节点,其值为 nums 中的最大值 递归地在最大值 左边 的 子数组前缀上 构建左子树 递归地在最大值 右边 的 子数组后缀上 构建右子树 1. 暴力分治构造 暴力在于每次递归都要找一次最大

  • leetcode 225. Implement Stack using Queues 用队列实现栈(简单)2022-08-19 17:00:08

    一、题目大意 请你仅使用两个队列实现一个后入先出(LIFO)的栈,并支持普通栈的全部四种操作(push、top、pop 和 empty)。 实现 MyStack 类: void push(int x) 将元素 x 压入栈顶。 int pop() 移除并返回栈顶元素。 int top() 返回栈顶元素。 boolean empty() 如果栈是空的,返回 true ;否则,

  • leetcode数组题目2022-08-19 09:01:15

    1.两数之和 1.1 题目描述 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 你可以按任意顺序返回答案。 1.2 示

  • LeetCode/函数的独占时间2022-08-19 00:31:51

    有一个单线程CPU 正在运行一个含有 n 道函数的程序。每道函数都有一个位于 0 和 n-1 之间的唯一标识符 函数调用存储在一个调用栈 上 :当一个函数调用开始时,它的标识符将会推入栈中。而当一个函数调用结束时,它的标识符将会从栈中弹出。标识符位于栈顶的函数是 当前正在执行的函数

  • LeetCode/最大相等频率2022-08-18 01:00:48

    给你一个正整数数组 nums,请你帮忙从该数组中找出能满足下面要求的最长前缀,并返回该前缀的长度 从前缀中恰好删除一个元素后,剩下每个数字的出现次数都相同。 1. 双哈希表 一个记录每个值的频数,一个记录每个频数的个数 class Solution { public: int maxEqualFreq(vector<int>&

  • LeetCode 127 Word Ladder2022-08-17 04:30:08

    A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that: Every adjacent pair of words differs by a single letter. Every si for 1 <= i <

  • [Leetcode Weekly Contest]3062022-08-16 21:31:23

    链接:LeetCode [Leetcode]2373. 矩阵中的局部最大值 给你一个大小为 n x n 的整数矩阵 grid 。 生成一个大小为 (n - 2) x (n - 2) 的整数矩阵 maxLocal ,并满足: maxLocal[i][j] 等于 grid 中以 i + 1 行和 j + 1 列为中心的 3 x 3 矩阵中的 最大值 。 换句话说,我们希望找出 grid

  • LeetCode 169 Majority Element2022-08-16 03:01:55

    Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Solution 利用投票法即可:遇到相同的元素,就将计数器加一;否

  • LeetCode 反转链表算法题解 All In One2022-08-15 23:30:09

    LeetCode 反转链表算法题解 All In One js / ts 实现反转链表 反转链表原理 图解 双指针,swap 交换 // 反转 双指针 // swap: a = b; c = a; b = c; let prev: ListNode | null = null; let cur: ListNode | null = head; // while(cur) { // // ES5 swap 缓存引用

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有