leetcode

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

commit 3ec73fcc24e0cbc771909f3c43f15e9be8150531
parent 50ceb6cb139a852ef23cb85c23d7940474c2c499
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat,  8 Jun 2024 13:54:21 +0200

Daily Problem

Diffstat:
AProblems/0523.cpp | 15+++++++++++++++
MREADME.md | 1+
2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/Problems/0523.cpp b/Problems/0523.cpp @@ -0,0 +1,15 @@ +class Solution { + public: + bool checkSubarraySum(const vector<int> &nums, int k) const { + unordered_set<int> seen; + + for (int i = 0, sum = 0, pre = 0; i < size(nums); i++) { + sum += nums[i]; + if (seen.count(sum % k)) return true; + seen.insert(pre); + pre = sum % k; + } + + return false; + } +}; diff --git a/README.md b/README.md @@ -371,6 +371,7 @@ for solving problems. | 0516 | Medium | [Longest Palindromic Subsequence](Problems/0516.cpp) | | 0518 | Medium | [Coin Change II](Problems/0518.cpp) | | 0520 | Easy | [Detect Capital](Problems/0520.cpp) | +| 0523 | Medium | [Continuous Subarray Sum](Problems/0523.cpp) | | 0524 | Medium | [Longest Word in Dictionary through Deleting](Problems/0524.cpp) | | 0525 | Medium | [Contiguous Array](Problems/0525.cpp) | | 0526 | Medium | [Beautiful Arrangement](Problems/0526.cpp) |