leetcode

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

commit 04e6243c32ea467babf67893b2ec92c90a7d1511
parent cfea103a9fe86ffa217009c1fad8b5dc28524bdc
author Dimitrije Dobrota <mail@dimitrijedobrota.com>
date Fri, 14 Jun 2024 16:32:27 +0200

1 Random Problem

Diffstat:
A Problems/1410.cpp | +++++++++++++++++++++++++++++++++
M README.md | +

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


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

@@ -0,0 +1,33 @@
class Solution {
public:
string entityParser(const string &text) const {
unordered_map<string, char> um = {{"&quot;", '"'}, {"&apos;", '\''}, {"&amp;", '&'},
{"&gt;", '>'}, {"&lt;", '<'}, {"&frasl;", '/'}};
string res, crnt;
for (const char c : text) {
if (crnt.empty()) {
if (c != '&')
res += c;
else
crnt = "&";
} else {
if (c == '&') {
res += crnt;
crnt = "&";
} else {
crnt += c;
if (c == ';') {
if (um.count(crnt))
res += um[crnt];
else
res += crnt;
crnt.clear();
}
}
}
}
return res + crnt;
}
};

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

@@ -797,6 +797,7 @@ for solving problems. | 1406 | Hard | [Stone Game III](Problems/1406.cpp) | | 1407 | Easy | [Top Travellers](Problems/1407.cpp) | | 1409 | Medium | [Queries on a Permutation With Key](Problems/1409.cpp) |
| 1410 | Medium | [HTML Entity Parser](Problems/1410.cpp) |
| 1414 | Medium | [Find the Minimum Number of Fibonacci Numbers Whose Sum Is K](Problems/1414.cpp) | | 1415 | Medium | [The k-th Lexicographical String of All Happy Strings of Length n](Problems/1415.cpp) | | 1416 | Hard | [Restore The Array](Problems/1416.cpp) |