题解 | 旺仔哥哥转圈圈

旺仔哥哥转圈圈

https://www.nowcoder.com/practice/739afacabadd463d9b73b23514bb6d5d

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 计算出旺仔哥哥最后会站在哪位小朋友旁边
# @param a int整型一维数组 第 i 个小朋友的数字是 a_i
# @param m int整型 表示旺仔哥哥的移动次数
# @return int整型
#
class Solution:
    def stopAtWho(self , a: List[int], m: int) -> int:
        # write code here
        index = 0   #起始下标
        step = a[0] #起始步伐
        for _ in range(m):
            index = (index - step)%len(a)#逆时针走到的位置
            step = a[index]#下一次所走的步伐
        
        return index+1

全部评论

相关推荐

程序员牛肉:继续沉淀吧同学,你这就是纯纯的流水线产品。 差不多的学历+两个烂大街项目。自身学历又不行,现在找啥实习呢。有点太浮躁了。多花点心思搞搞ai,开源和八股。这比你这段时间捣鼓一段小厂实习要好得多;
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务