标签:https foreach target com string problem color problems log
public class Solution { Stack<char> S = new Stack<char>(); public bool IsValid(string s) { foreach (var c in s) { if (c == ‘(‘ || c == ‘[‘ || c == ‘{‘) { S.Push(c); } else if(c == ‘)‘) { if (S.Count > 0) { var k = S.Peek(); if (k == ‘(‘) { S.Pop(); } else { return false; } } else { return false; } } else if (c == ‘]‘) { if (S.Count > 0) { var k = S.Peek(); if (k == ‘[‘) { S.Pop(); } else { return false; } } else { return false; } } else if (c == ‘}‘) { if (S.Count > 0) { var k = S.Peek(); if (k == ‘{‘) { S.Pop(); } else { return false; } } else { return false; } } } if (S.Count > 0) { return false; } else { return true; } } }
https://leetcode.com/problems/valid-parentheses/#/description
标签:https foreach target com string problem color problems log
原文地址:http://www.cnblogs.com/asenyang/p/6758974.html