### LeetCode 20 Valid Parentheses

* Given a string s containing just the characters '(', ')', '{', '}', '[', ']', determine if the input string is valid.
* An input string is valid if:
* 1. Open brackets must be closed by the same type of brackets.
* 2. Open brackets must be closed in the correct order.

#region LeetCode 20 Valid Parentheses
/*
* Given a string s containing just the characters '(', ')', '{', '}', '[', ']', determine if the input string is valid.
* An input string is valid if:
* 1. Open brackets must be closed by the same type of brackets.
* 2. Open brackets must be closed in the correct order.
*
* Input : "()"
* Output : true
*
* Input : "()[]{}"
* Output : true
*
* Input : "(]"
* Output : false
*
* Input : "[()]"
* Output : true
*/
public bool LeetCode_20(string s)
{
bool ans = false;
int i = 0;
string buf = "";

if (s.Length == 0)
return ans;

while (i != s.Length - 1)
{
if (i < s.Length - 1)
{
buf = s.Substring(i, 2);
if (buf == "()" || buf == "[]" || buf == "{}")
{
s = s.Remove(i, 2);
i = 0;
}
else
{
i++;
}
}

if(s.Length == 0)
{
ans = true;
break;
}
}

return ans;
}
#endregion