LeetCode 21:合并两个有序链表(Merge Two Sorted Lists)解法汇总

更多LeetCode题解

有序链表的归并排序,很简单

class Solution {
public:
	bool isValid(string s) {
		stack<char> sta;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == '(' || s[i] == '[' || s[i] == '{') {
				sta.push(s[i]);
			}
			else if (s[i] == ')') {
				if (sta.empty() || sta.top() != '(') {
					return false;
				}
				else {
					sta.pop();
				}
			}
			else if (s[i] == ']') {
				if (sta.empty() || sta.top() != '[') {
					return false;
				}
				else {
					sta.pop();
				}
			}
			else if (s[i] == '}') {
				if (sta.empty() || sta.top() != '{') {
					return false;
				}
				else {
					sta.pop();
				}
			}
		}
		if (!sta.empty()) {
			return false;
		}
		return true;
	}
};

你可能感兴趣的:(LeetCode刷题题解记录,LeetCode,合并两个有序链表,Merge,Two,Sorted,Lists)