summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-05-21 15:14:10 +0800
committercrupest <crupest@outlook.com>2020-05-21 15:14:10 +0800
commite3efc844f67b0cfa9410caee79a7e9354800387d (patch)
tree2d13c0f8eda520d442b0bd18855bd0ee4708f846
parentaee7cb0b0c15ecb364e811a2230337f90b870ff4 (diff)
downloadsolutions-e3efc844f67b0cfa9410caee79a7e9354800387d.tar.gz
solutions-e3efc844f67b0cfa9410caee79a7e9354800387d.tar.bz2
solutions-e3efc844f67b0cfa9410caee79a7e9354800387d.zip
Add problem 680 .
-rw-r--r--cpp/680.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/cpp/680.cpp b/cpp/680.cpp
new file mode 100644
index 0000000..21d150f
--- /dev/null
+++ b/cpp/680.cpp
@@ -0,0 +1,35 @@
+#include <string>
+
+using std::string;
+
+bool strict_palindrome(string::const_iterator left, string::const_iterator right)
+{
+ while (left < right)
+ {
+ if (*left != *right)
+ return false;
+ ++left;
+ --right;
+ }
+ return true;
+}
+
+class Solution
+{
+public:
+ bool validPalindrome(string s)
+ {
+ string::const_iterator left = s.cbegin();
+ string::const_iterator right = s.cend() - 1;
+
+ while (left < right)
+ {
+ if (*left != *right)
+ return strict_palindrome(left, right - 1) || strict_palindrome(left + 1, right);
+
+ ++left;
+ --right;
+ }
+ return true;
+ }
+};