leetcode

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

commit 87b75f390e210deb016066b80383bd623ca428ba
parent c885e6210b65a98bbc0ab30deb6b525e4481a990
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sun, 15 Sep 2024 12:28:38 +0200

1 Random Problem

Diffstat:
AProblems/0831.cpp | 38++++++++++++++++++++++++++++++++++++++
MREADME.md | 1+
2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/Problems/0831.cpp b/Problems/0831.cpp @@ -0,0 +1,38 @@ +class Solution { + public: + string maskPII(string &s) const { + const auto at = s.find('@'); + string res; + + if (at != string::npos) { + res += tolower(s[0]); + res += "*****"; + res += tolower(s[at - 1]); + for (int i = at; i < size(s); i++) + res += tolower(s[i]); + } else { + int digits = 0; + for (const char c : s) + digits += isdigit(c); + + if (digits == 10) + res += "***-***-"; + else if (digits == 11) + res += "+*-***-***-"; + else if (digits == 12) + res += "+**-***-***-"; + else if (digits == 13) + res += "+***-***-***-"; + + string extra; + for (int i = size(s) - 1; size(extra) < 4; i--) { + if (!isdigit(s[i])) continue; + extra = s[i] + extra; + } + + res += extra; + } + + return res; + } +}; diff --git a/README.md b/README.md @@ -524,6 +524,7 @@ for solving problems. | 0823 | Medium | [Binary Trees With Factors](Problems/0823.cpp) | | 0826 | Medium | [Most Profit Assigning Work](Problems/0826.cpp) | | 0830 | Medium | [Kth Smallest Element in a BST](Problems/0230.cpp) | +| 0831 | Medium | [Masking Personal Information](Problems/0831.cpp) | | 0833 | Medium | [Find And Replace in String](Problems/0833.cpp) | | 0834 | Hard | [Sum of Distances in Tree](Problems/0834.cpp) | | 0835 | Medium | [Image Overlap](Problems/0835.cpp) |