LeetCode】每日一题 2024_9_21 边积分最高的节点(哈希)

前言 每天和你一起刷 LeetCode 每日一题~ LeetCode 启动! 题目:边积分最高的节点 代码与解题思路 func edgeScore(edges []int) (ans int) { // 直接维护哈希最大值即可 mp := map[int]int{} for i, v := range edges { mp[v] += i // 如果多个节点的 边积分 相同,返回编号 最小 的那个。 if mp...

LeetCode //C - 401. Binary Watch

is not valid. It should be “10:02”.   Example 1: Example 2: Constraints: 0 <= turnedOn <= 10 From: LeetCode Link: 401. Binary Watch Solution: Ideas: 1. Dynamic Resizing: I introduced a variable capacity to t...

LeetCode:219. 存在重复元素 II + 哈希表】

🍔 目录 🚩 题目链接⛲ 题目描述🌟 求解思路&实现代码&运行结果⚡ 哈希表🥦 求解思路🥦 实现代码🥦 运行结果 💬 共勉 🚩 题目链接 219. 存在重复元素 II ⛲ 题目描述 给你一个整数数组 nums 和一个整数 k ,判断数组中是否存在两个 不同的索引 i 和 j ,满足 nums[i] == nums[j] 且 abs(i - j) <= k 。如果存在,返回 true ;否则,返回 false 。...

LeetCode】每日一题 2024_9_13 预算内的最多机器人数目(滑动窗口、单调队列)

LeetCode 启动! 每日一题的题解重新开始连载! 题目:预算内的最多机器人数目 题目链接:2398. 预算内的最多机器人数目 题目描述 代码与解题思路 func maximumRobots(chargeTimes []int, runningCosts []int, budget int64) (ans int) { l, sum, mx := 0, 0, []int{0} for r := range ...

LeetCode //C - 371. Sum of Two Integers

thout using the operators + and -.   Example 1: Example 2: Constraints: -1000 <= a, b <= 1000 From: LeetCode Link: 371. Sum of Two Integers Solution: Ideas: 1. XOR (^) for Sum Without Carry The XOR operation ...

LeetCode - 15 三数之和

题目来源 15. 三数之和 - 力扣(LeetCode) 题目描述 给你一个整数数组 nums ,判断是否存在三元组 [nums[i], nums[j], nums[k]] 满足 i != j、i != k 且 j != k ,同时还满足 nums[i] + nums[j] + nums[k] == 0 。请你返回所有和为 0 且不重复的三元组。 注意:答案中不可以包含重复的三元组。 示例 1 示例 2 示例 3...

LeetCode - 16 最接近的三数之和

题目来源 16. 最接近的三数之和 - 力扣(LeetCode)   题目描述 给你一个长度为 n 的整数数组 nums 和 一个目标值 target。请你从 nums 中选出三个整数,使它们的和与 target 最接近。 返回这三个数的和。 假定每组输入只存在恰好一个解。 示例 1 示例 2 提示 3 <= nums.length <= 1000-1000 <= nums[i] <= 1000-10^4 <= ...

【三元组枚举中点】【树状数组】个人练习-Leetcode-1395. Count Number of Teams

题目链接:https://leetcode.cn/problems/count-number-of-teams/description/ 题目大意:给一个数组rating[],求符合以下任一条件的三元组i, j, k的个数 rating[i] < rating[j] < rating[k]rating[i] > rating[j] > rating[k] 其实就是递增和递减。 思路:暴力枚举当然不太行。那么怎么...

LeetCode //C - 335. Self Crossing

ength<=105 1 < = d i s t a n c e [ i ] < = 1 0 5 1 <= distance[i] <= 10^5 1<=distance[i]<=105 From: LeetCode Link: 335. Self Crossing Solution: Ideas: Case 1: When the current move makes a cross with the move...

[LeetCode]139.单词拆分(C++)

1.代码 class Solution {public: bool wordBreak(string s, vector<string>& wordDict) { int length = s.size(); bool *count1 = new bool[length+1]; fill(count1, count1 + length + 1, false); unordered_map<string, boo...
© 2024 LMLPHP 关于我们 联系我们 友情链接 耗时0.013760(s)
2024-10-23 03:09:44 1729624184