leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | c44453845ac5b4ca1cdabae40a93859ed66f7211 |
parent | 7ea2dcb4b0e9d46039aaa23138730fcf27725718 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Fri, 27 Oct 2023 17:22:41 +0000 |
1 Random Problem
Diffstat:A | Problems/2150.cpp | | | +++++++++++++++++ |
M | README.md | | | + |
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/Problems/2150.cpp b/Problems/2150.cpp
@@ -0,0 +1,17 @@
class Solution {
public:
vector<int> findLonely(vector<int> &nums) {
sort(begin(nums), end(nums));
vector<int> res;
const int n = nums.size() - 1;
for (int i = 0; i <= n; i++) {
if (i < n && nums[i] == nums[i + 1]) continue;
if (i > 0 && nums[i] == nums[i - 1]) continue;
if (i > 0 && nums[i] - 1 == nums[i - 1]) continue;
if (i < n && nums[i] + 1 == nums[i + 1]) continue;
res.push_back(nums[i]);
}
return res;
}
};
diff --git a/README.md b/README.md
@@ -773,6 +773,7 @@ for solving problems.
| 2140 | Medium | [Solving Questions With Brainpower](Problems/2140.cpp) |
| 2141 | Hard | [Maximum Running Time of N Computers](Problems/2141.cpp) |
| 2149 | Medium | [Rearrange Array Elements by Sign](Problems/2149.cpp) |
| 2150 | Medium | [Find All Lonely Numbers in the Array](Problems/2150.cpp) |
| 2155 | Medium | [All Divisions With the Highest Score of a Binary Array](Problems/2155.cpp) |
| 2161 | Medium | [Partition Array According to Given Pivot](Problems/2161.cpp) |
| 2177 | Medium | [Find Three Consecutive Integers That Sum to a Given Number](Problems/2177.cpp) |