leetcode刷题 6061

    xiaoxiao2022-07-06  181

    官方题解

    import math class Solution: def getPermutation(self, n: int, k: int) -> str: nums = list(range(1,n+1)) out = '' while n>1: temp = math.factorial(n-1) #print(k,temp) pos = (k-1)//temp k = k%temp nn = nums[pos] out += str(nn) nums.remove(nn) n -= 1 return out+str(nums[-1])

    官方题解

    class Solution: def rotateRight(self, head: ListNode, k: int) -> ListNode: if not head: return None p=q=head l=1 while p.next: p=p.next l+=1 p.next=head k%=l for _ in range(l-k-1): q=q.next ans=q.next q.next=None return ans 刘润森! 认证博客专家 Python Java 前端 17年就读于东莞XX学院化学工程与工艺专业,GitChat作者。Runsen的微信公众号是"Python之王",因为Python入了IT的坑,从此不能自拔。公众号内容涉及Python,Java计算机、杂谈。干货与情怀同在。喜欢的微信搜索:「Python之王」。个人微信号:RunsenLiu。不关注我公号一律拉黑!!!
    最新回复(0)