Random commentary about Machine Learning, BigData, Spark, Deep Learning, C++, STL, Boost, Perl, Python, Algorithms, Problem Solving and Web Search
int par = 0;for(int i = 0; i < str.length; i++) { // str != null char ch = str.charAt(i); if (ch == '(') par++; if (ch == ')') par--; if (par < 0) return false;}It seems suspiciously simple. Am I missing something?
int par = 0;
ReplyDeletefor(int i = 0; i < str.length; i++) { // str != null
char ch = str.charAt(i);
if (ch == '(') par++;
if (ch == ')') par--;
if (par < 0) return false;
}
It seems suspiciously simple. Am I missing something?