All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 13, 2024
Last updated : July 01, 2024
Related Topics : Linked List, Math, Number Theory
Acceptance Rate : 88.681 %
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def insertGreatestCommonDivisors(self, head: Optional[ListNode]) -> Optional[ListNode]:
curr = head
while curr and curr.next :
curr.next = ListNode(val=gcd(curr.val, curr.next.val), next=curr.next)
curr = curr.next.next
return head