Created
July 10, 2009 08:51
-
-
Save dazza/144353 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <string> | |
#include <algorithm> | |
#include <cmath> | |
using namespace std; | |
class CompletingBrackets { | |
public: | |
string complete(string text) | |
{ | |
int nLeft = 0;//']' | |
int nRight = 0; | |
for(int i = 0 ; i < text.size(); i++) | |
{ | |
if(text[i] == '[') | |
{ | |
nRight++; | |
} | |
else | |
{ | |
if (nRight==0) | |
nLeft++; | |
else | |
nRight--; | |
} | |
} | |
return string(nLeft,'[')+text+string(nRight,']'); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment