Skip to content

Commit

Permalink
Update remove-duplicate-letters.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 committed Dec 9, 2015
1 parent ae1787e commit dce7c56
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions C++/remove-duplicate-letters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Solution {
vector<bool> visited(k);
string stk;
for (const auto& c : s) {
if (!visited[c - 'a'] && (stk.empty() || stk.back() != c)) {
while (!stk.empty() && stk.back() >= c && cnts[stk.back() - 'a'] > 0) {
if (!visited[c - 'a']) {
while (!stk.empty() && stk.back() > c && cnts[stk.back() - 'a']) {
visited[stk.back() - 'a'] = false;
stk.pop_back();
}
Expand All @@ -42,8 +42,8 @@ class Solution2 {
unordered_set<char> visited;
string stk;
for (const auto& c : s) {
if (!visited.count(c) && (stk.empty() || stk.back() != c)) {
while (!stk.empty() && stk.back() >= c && cnts[stk.back()] > 0) {
if (!visited.count(c)) {
while (!stk.empty() && stk.back() > c && cnts[stk.back()]) {
visited.erase(stk.back());
stk.pop_back();
}
Expand Down

0 comments on commit dce7c56

Please sign in to comment.