From 0c5f8be571a77bd32460f21406b706d25ce9752f Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Sun, 7 Apr 2024 19:03:34 +0530 Subject: [PATCH] Create 678. Valid Parenthesis String --- 678. Valid Parenthesis String | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 678. Valid Parenthesis String diff --git a/678. Valid Parenthesis String b/678. Valid Parenthesis String new file mode 100644 index 0000000..ce5b34a --- /dev/null +++ b/678. Valid Parenthesis String @@ -0,0 +1,19 @@ +#include +#include +#include + +using namespace std; + +class Solution { +public: + bool checkValidString(string s) { + int low = 0, high = 0; + for (char c : s) { + low += (c == '(') ? 1 : -1; + high += (c != ')') ? 1 : -1; + if (high < 0) return false; + low = max(low, 0); + } + return low == 0; + } +};