首页 > 其他分享 >LeetCode-day30-2961. 双模幂运算

LeetCode-day30-2961. 双模幂运算

时间:2024-07-30 14:28:36浏览次数:11  
标签:10 下标 target 示例 variables day30 2961 LeetCode 1000

LeetCode-day30-2961. 双模幂运算

题目描述

给你一个下标从 0 开始的二维数组 variables ,其中 variables[i] = [ai, bi, ci, mi],以及一个整数 target 。

如果满足以下公式,则下标 i 是 好下标

  • 0 <= i < variables.length
  • ((aibi % 10)ci) % mi == target

返回一个由 好下标 组成的数组,顺序不限

示例

示例1:

输入:variables = [[2,3,3,10],[3,3,3,1],[6,1,1,4]], target = 2
输出:[0,2]
解释:对于 variables 数组中的每个下标 i :
对于下标 0 ,variables[0] = [2,3,3,10] ,(23 % 10)3 % 10 = 2 。
对于下标 1 ,variables[1] = [3,3,3,1] ,(33 % 10)3 % 1 = 0 。
对于下标 2 ,variables[2] = [6,1,1,4] ,(61 % 10)1 % 4 = 2 。
因此,返回 [0,2] 作为答案。

示例2:

输入:variables = [[39,3,1000,1000]], target = 17
输出:[ ]
解释:对于 variables 数组中的每个下标 i :
对于下标 0 ,variables[0] = [39,3,1000,1000] ,(393 % 10)1000 % 1000 = 1 。
因此,返回 [ ] 作为答案。

思路

幂次方,暴力循环

代码

class Solution:
    def getGoodIndices(self, variables: List[List[int]], target: int) -> List[int]:
        res = []
        for i,x in enumerate(variables):
            ans =((x[0]**x[1] % 10) ** x[2]) % x[3]
            if ans == target:
                res.append(i)
        return res

标签:10,下标,target,示例,variables,day30,2961,LeetCode,1000
From: https://blog.csdn.net/weixin_43344005/article/details/140794420

相关文章

  • LeetCode 756. Pyramid Transition Matrix
    原题链接在这里:https://leetcode.com/problems/pyramid-transition-matrix/description/题目:Youarestackingblockstoformapyramid.Eachblockhasacolor,whichisrepresentedbyasingleletter.Eachrowofblockscontains onelessblock thantherowbenea......
  • LeetCode面试150——121买卖股票的最佳时机
    题目难度:简单默认优化目标:最小化平均时间复杂度。Python默认为Python3。目录1题目描述2题目解析3算法原理及程序实现3.1暴力求解3.2动态规划参考文献1题目描述给定一个数组prices,它的第i个元素prices[i]表示一支给定股票第i天的价格。你只能选择......
  • 代码随想录——完全平方数(Leetcode 279)
    题目链接动态规划动态规划思路:状态定义:定义一个一维数组dp,其中dp[i]表示组成整数i所需的最少完全平方数的数量。状态初始化:将dp数组中的所有元素初始化为Integer.MAX_VALUE,表示初始状态下组成每个整数的完全平方数数量是无限大(即不可能)。但dp[0]需要初始化为0,因为组成......
  • 《LeetCode热题100》---<双指针篇四道>
    本篇博客讲解LeetCode热题100道双指针篇中的第一道:移动零(简单)第二道:盛最多水的容器(中等)第一道:移动零(简单)classSolution{publicvoidmoveZeroes(int[]nums){for(intcur=0,dest=-1;cur<nums.length;cur++){//采用双指针......
  • LeetCode - #107 二叉树的层序遍历 II
    文章目录前言1.描述2.示例3.答案关于我们前言我们社区陆续会将顾毅(Netflix增长黑客,《iOS面试之道》作者,ACE职业健身教练。)的Swift算法题题解整理为文字版以方便大家学习与阅读。LeetCode算法到目前我们已经更新到105期,我们会保持更新时间和进度(周一、......
  • LeetCode之vector
    目录前言1.杨辉三角2.删除有序数组的重复项3.只出现一次的数字Ⅲ只出现一次的数字Ⅱ数组中出现次数超过一半的数字补充讲解sort()前言本篇是对vector的一个巩固练习,题目分别在leetcode和牛客网博客主页:酷酷学!!!感谢关注~正文开始1.杨辉三角题目思路......
  • leetcode-9
    题目:给你一个整数 x ,如果 x 是一个回文整数,返回 true ;否则,返回 false 。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。例如,121 是回文,而 123 不是推导:自己硬写的。代码:1classSolution{2public:3boolisPalindrome(intx){4......
  • LeetCode682
    classSolution{  publicintcalPoints(String[]operations){    int[]a=newint[1000];    intj=0;    intsum=0;    for(inti=0;i<operations.length;i++){        if("+".equals(operations[i])){ ......
  • LeetCode LCR 124.推理二叉树(哈希表 + 建树)
    某二叉树的先序遍历结果记录于整数数组 preorder,它的中序遍历结果记录于整数数组 inorder。请根据 preorder 和 inorder 的提示构造出这棵二叉树并返回其根节点。注意:preorder 和 inorder 中均不含重复数字。示例1:输入:preorder=[3,9,20,15,7],inorder=......
  • leetcode-8,真恶心
    题目:请你来实现一个 myAtoi(strings) 函数,使其能将字符串转换成一个32位有符号整数。推导:代码:1classAutomaton{2public:3intsign=1;//初始化默认符号4longlongans=0;//初始化整数5unordered_map<string,vector<string>>table......