leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE |

commit241b4dd44579acdcb40aeef5643e5fb9fe834113
parentfdda3bddaf44ad2808c1041045946c2fc419a6ec
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateMon, 7 Aug 2023 09:49:00 +0200

Random Problem

Diffstat:
AProblems/2807.cpp|++++++++++++++++++
MREADME.md|+

2 files changed, 19 insertions(+), 0 deletions(-)


diff --git a/Problems/2807.cpp b/Problems/2807.cpp

@@ -0,0 +1,18 @@

class Solution {
int gcd(int a, int b) {
if (!a) return b;
if (!b) return a;
return gcd(b, a % b);
}
public:
ListNode *insertGreatestCommonDivisors(ListNode *head) {
ListNode *crnt = head, *next = head->next;
while (next) {
crnt->next = new ListNode(gcd(crnt->val, next->val), next);
crnt = next;
next = next->next;
}
return head;
}
};

diff --git a/README.md b/README.md

@@ -626,3 +626,4 @@ for solving problems.

| 2666 | Easy | [Allow One Function Call](Problems/2666.js) |
| 2667 | Easy | [Create Hello World Function](Problems/2667.js) |
| 2676 | Medium | [Throttle](Problems/2676.js) |
| 2807 | Medium | [Insert Greatest Common Divisors in Linked List](Problems/2807.cpp) |