From 4cf8a8359211c9e3502baa85afb4ce5fcf028d95 Mon Sep 17 00:00:00 2001 From: axayjha Date: Wed, 14 Oct 2020 10:45:12 +0530 Subject: [PATCH] fixing linting issues --- dynamic_programming/word_break.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/dynamic_programming/word_break.cpp b/dynamic_programming/word_break.cpp index 2806d5763..6de8eaf8d 100644 --- a/dynamic_programming/word_break.cpp +++ b/dynamic_programming/word_break.cpp @@ -24,8 +24,7 @@ Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"] Output: false */ -#include - +#include #include #include #include @@ -39,40 +38,40 @@ using std::vector; class Solution { public: - bool exists(const string s, const unordered_set strSet) { + bool exists(const string &s, const unordered_set &strSet) { return strSet.find(s) != strSet.end(); } - bool check(const string s, const unordered_set strSet, int pos, - vector& dp) { + bool check(const string &s, const unordered_set &strSet, int pos, + vector *dp) { if (pos == s.length()) { return true; } - if (dp[pos] != INT_MAX) { - return dp[pos] == 1; + if (dp->at(pos) != INT_MAX) { + return dp->at(pos) == 1; } string wordTillNow = ""; for (int i = pos; i < s.length(); i++) { wordTillNow += string(1, s[i]); if (exists(wordTillNow, strSet) and check(s, strSet, i + 1, dp)) { - dp[pos] = 1; + dp->at(pos) = 1; return true; } } - dp[pos] = 0; + dp->at(pos) = 0; return false; } - bool wordBreak(const string s, const vector& wordDict) { + bool wordBreak(const string &s, const vector &wordDict) { unordered_set strSet; - for (const auto s : wordDict) { + for (const auto &s : wordDict) { strSet.insert(s); } vector dp(s.length(), INT_MAX); - return check(s, strSet, 0, dp); + return check(s, strSet, 0, &dp); } };