leetcode

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

commit d9935a53df6cb1f051f901a8bcc8176846c09c14
parent 9d42e89b09962ba23e0a946d9563047635eebc68
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Tue,  6 Jun 2023 11:31:10 +0200

Daily Problem

Diffstat:
AProblems/1502.cpp | 13+++++++++++++
MREADME.md | 1+
2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/Problems/1502.cpp b/Problems/1502.cpp @@ -0,0 +1,13 @@ +class Solution { +public: + bool canMakeArithmeticProgression(vector<int> &arr) { + int n = arr.size(); + if (n <= 2) return true; + sort(arr.begin(), arr.end()); + int delta = arr[1] - arr[0]; + for (int i = 2; i < n; i++) { + if (arr[i] - arr[i - 1] != delta) return false; + } + return true; + } +}; diff --git a/README.md b/README.md @@ -466,6 +466,7 @@ for solving problems. | 1489 | Hard | [Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree](Problems/1489.cpp) | | 1491 | Easy | [Average Salary Excluding the Minimum and Maximum Salary](Problems/1491.cpp) | | 1498 | Medium | [Number of Subsequences That Satisfy the Given Sum Condition](Problems/1498.cpp) | +| 1502 | Easy | [Can Make Arithmetic Progression From Sequence](Problems/1502.cpp) | | 1514 | Medium | [Path with Maximum Probability](Problems/1514.cpp) | | 1519 | Medium | [Number of Nodes in the Sub-Tree With the Same Label](Problems/1519.cpp) | | 1523 | Easy | [Count Odd Numbers in an Interval Range](Problems/1523.cpp) |