Re: [闲聊] 每日leetcode

楼主: DJYOMIYAHINA (通通打死)   2024-09-10 21:25:31
我好像第一次用gcd这个function
不过要我写我也不知道怎么写
辗转相除法好难
def insertGreatestCommonDivisors(self, head: Optional[ListNode]) ->
Optional[ListNode]:
headdd = head
while head:
pre = head
head = head.next
if head:
pre.next = ListNode(math.gcd(pre.val, head.val))
pre.next.next = head
return headdd
作者: nh60211as   2024-09-10 21:26:00
std::gcd
作者: sustainer123 (caster)   2024-09-10 21:27:00
if y==0 return x else return gcd(y,x%y)递回长这样 循环我忘了

Links booklink

Contact Us: admin [ a t ] ucptt.com