网站首页 站内搜索

搜索结果

查询Tags标签: nums,共有 1882条记录
  • 398. 随机数索引

    labuladong 题解思路 难度中等247收藏分享切换为英文接收动态反馈给你一个可能含有 重复元素 的整数数组 nums ,请你随机输出给定的目标数字 target 的索引。你可以假设给定的数字一定存在于数组中。 实现 Solution 类:Solution(int[] nums) 用数组 nums 初始化对象。 i…

    2022/8/25 6:24:20 人评论 次浏览
  • [Leetcode Weekly Contest]307

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

    2022/8/25 6:24:19 人评论 次浏览
  • 动态规划——leetcode55、跳跃游戏

    题目描述: 解题方法:动态规划动态规划解题步骤:确定状态:最后一步:如果能跳到最后一个下标,我们考虑他的最后一步到n-1(最后一个下标),这一步是从 i 跳过来的,i<n-1;    这需要满足两个条件:可以跳到 i ; 最后一步跳跃的距离 <= 从i可以跳跃的最大…

    2022/8/24 23:26:34 人评论 次浏览
  • 1. Two Sum #

    1. Two Sum # 题目 # Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Example: Given nu…

    2022/8/24 23:25:13 人评论 次浏览
  • [Oracle] LeetCode 1802 Maximum Value at a Given Index in a Bounded Array

    You are given three positive integers: n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions:nums.length == n nums[i] is a positive integer where 0 <= i < n. abs(nums[i] - nums[i+1]) <= …

    2022/8/24 2:23:15 人评论 次浏览
  • [题解]轮流拿牌问题_一道博弈论笔试题(C++)

    题目 A和B轮流从一个数组左右两端取数,A先B后,每次取一个数,最终取数总和大者获胜,两人每次都会选择最有利的策略,求获胜者取数的和。 思路 笔试时遇到的一道算法题,也是博弈论中非常经典的入门题目了。从先后手的角度考虑,先手在行动一次后获得左右两端数中的一个…

    2022/8/24 1:24:22 人评论 次浏览
  • LeetCode 34. 在排序数组中查找元素的第一个和最后一个位置

    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() - 1;…

    2022/8/22 23:24:27 人评论 次浏览
  • 219. 存在重复元素 II

    思路 难度简单506收藏分享切换为英文接收动态反馈给你一个整数数组 nums 和一个整数 k ,判断数组中是否存在两个 不同的索引 i 和 j ,满足 nums[i] == nums[j] 且 abs(i - j) <= k 。如果存在,返回 true ;否则,返回 false 。示例 1: 输入:nums = [1,2,3,1], k= …

    2022/8/22 6:57:09 人评论 次浏览
  • Maximum Segment Sum After Removals

    Maximum Segment Sum After Removals You are given two 0-indexed integer arrays $nums$ and $removeQueries$, both of length $n$. For the $i^{th}$ query, the element in $nums$ at the index $removeQueries[i]$ is removed, splitting $nums$ into different seg…

    2022/8/21 23:54:27 人评论 次浏览
  • *Codeforces Round #766 (Div. 2) C. Not Assigning(dfs)

    https://codeforces.com/contest/1627/problem/C 给你一个n个顶点的树,顶点从1到n,边从1到n-1。树是没有圈的连通无向图。你必须给树的每条边分配整数权重,这样得到的图就是一个素数树。素数树是指由一条或两条边组成的每条路的重量都是素数的树。一条路径不应该访问任…

    2022/8/16 23:30:03 人评论 次浏览
  • 算法性能技巧

    算法性能提升总结 巧用hash表 利用hash,来进行映射,从而降低代码的复杂度,和冗余度 eg: 求两个数之和 class Solution:def twoSum(self, nums: List[int], target: int)->List[int]:"""暴力方法实现时间复杂度为O(n*n)"""n = len(num…

    2022/8/16 14:53:47 人评论 次浏览
  • LeetCode 169 Majority Element

    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 利用投票法即可:遇到相同的元素,就将计…

    2022/8/16 6:23:00 人评论 次浏览
  • 力扣-刷题-324. 摆动排序 II

    题目链接 来源:力扣(LeetCode) 链接:https://leetcode.cn/problems/wiggle-sort-ii 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 题目描述 给你一个整数数组 nums,将它重新排列成 nums[0] < nums[1] > nums[2] < nums[3]... 的顺…

    2022/8/15 23:24:07 人评论 次浏览
  • 定义Map时候 记得把类型写在定义的后面:在初始化时候写类型不好使

    定义Map时候 记得把类型写在定义的后面:在初始化时候写类型不好使 Map map = new HashMap<Integer, Integer>();for(int i=0;i< nums.length;i++){if(map.containsKey(nums[i])){//下一行会报错:Operator + cannot be applied to java.lang.Object, intint new…

    2022/8/13 23:28:32 人评论 次浏览
  • LeetCode 673 Number of Longest Increasing Subsequence

    Given an integer array nums, return the number of longest increasing subsequences. Notice that the sequence has to be strictly increasing. Solution 我们需要求出最长长度序列的个数。不妨用两个数组 \(dp1, dp2\). 其中 \(dp1[i]\) 表示以 \(i\) 结尾的最长递增…

    2022/8/13 6:23:25 人评论 次浏览
扫一扫关注最新编程教程