Avatar

Organizations

15 results for 数学
  • 给你一个正整数数组 arr ,请你计算所有可能的奇数长度子数组的和。

    子数组 定义为原数组中的一个连续子序列。

    请你返回 arr 中 所有奇数长度子数组的和

    leetcode 简单 数组 数学 前缀和 Created Fri, 02 Dec 2022 14:13:41 +0800
  • 给你一个整数数组 nums 。玩家 1 和玩家 2 基于这个数组设计了一个游戏。

    玩家 1 和玩家 2 轮流进行自己的回合,玩家 1 先手。开始时,两个玩家的初始分值都是 0。每一回合,玩家从数组的任意一端取一个数字(即,nums[0]nums[nums.length - 1]),取到的数字将会从数组中移除(数组长度减 1)。玩家选中的数字将会加到他的得分上。当数组中没有剩余数字可取时,游戏结束。

    如果玩家 1 能成为赢家,返回 true 。如果两个玩家得分相等,同样认为玩家 1 是游戏的赢家,也返回 true。你可以假设每个玩家的玩法都会使他的分数最大化。

    leetcode 中等 递归 数组 数学 Created Tue, 13 Sep 2022 13:43:09 +0800
  • Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.

    If the fractional part is repeating, enclose the repeating part in parentheses.

    If multiple answers are possible, return any of them.

    It is guaranteed that the length of the answer string is less than 104 for all the given inputs.

    leetcode 中等 哈希表 数学 字符串 Created Tue, 21 Jun 2022 15:53:27 +0800
  • Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator.

    The integer division should truncate toward zero, which means losing its fractional part. For example, 8.345 would be truncated to 8, and -2.7335 would be truncated to -2.

    Return the quotient after dividing dividend by divisor.

    leetcode 中等 位运算 数学 Created Tue, 21 Jun 2022 15:53:24 +0800
  • Implement pow(x, n), which calculates x raised to the power n (i.e., \(x^n\)).

    leetcode 中等 递归 数学 Created Tue, 21 Jun 2022 15:53:22 +0800
  • 实现RandomizedSet 类:

    • RandomizedSet() 初始化 RandomizedSet 对象
    • bool insert(int val) 当元素 val 不存在时,向集合中插入该项,并返回 true ;否则,返回 false
    • bool remove(int val) 当元素 val 存在时,从集合中移除该项,并返回 true ;否则,返回 false
    • int getRandom() 随机返回现有集合中的一项(测试用例保证调用此方法时集合中至少存在一个元素)。每个元素应该有 相同的概率 被返回。

    你必须实现类的所有函数,并满足每个函数的 平均 时间复杂度为 O(1)

    leetcode 中等 设计 数组 哈希表 Created Wed, 13 Apr 2022 15:22:28 +0800
  • Given four integers sx, sy, tx, and ty, return true if it is possible to convert the point (sx, sy) to the point (tx, ty) through some operations**, or false otherwise.

    The allowed operation on some point (x, y) is to convert it to either (x, x + y) or (x + y, y).

    leetcode 困难 数学 Created Sat, 09 Apr 2022 14:26:35 +0800
  • Given an integer num, repeatedly add all its digits until the result has only one digit, and return it.

    leetcode 简单 数学 数论 模拟 Created Thu, 03 Mar 2022 13:13:27 +0800
  • 给你一个整数数组  nums 。如果  nums  的一个子集中,所有元素的乘积可以表示为一个或多个 互不相同的质数 的乘积,那么我们称它为  好子集 。

    • 比方说,如果  nums = [1, 2, 3, 4] :
      • [2, 3] ,[1, 2, 3]  和  [1, 3]  是   子集,乘积分别为  6 = 2*3 ,6 = 2*3  和  3 = 3 。
      • [1, 4] 和  [4]  不是   子集,因为乘积分别为  4 = 2*2 和  4 = 2*2 。

    请你返回 nums  中不同的    子集的数目对 109 + 7 取余  的结果。

    nums  中的 子集  是通过删除 nums  中一些(可能一个都不删除,也可能全部都删除)元素后剩余元素组成的数组。如果两个子集删除的下标不同,那么它们被视为不同的子集。

    leetcode 困难 位运算 数组 数学 Created Tue, 22 Feb 2022 09:23:56 +0800
  • 给你一个下标从 0 开始、长度为 n 的整数数组 nums 和一个整数 k ,返回满足下述条件的下标对 (i, j) 的数目:

    • 0 <= i < j <= n - 1
    • nums[i] * nums[j] 能被 k 整除。
    leetcode 困难 计数 数学 Created Sun, 20 Feb 2022 12:30:41 +0800
Next