From 668dccc4a01867f51a63574d4587e76da6ff3524 Mon Sep 17 00:00:00 2001 From: Debojyoti Majumder Date: Thu, 30 May 2019 09:37:54 +0530 Subject: [PATCH] #24 Step towards fixing the TLE error Still need to fix other two test cases --- 2019Q1/cppWorkspace/leetcode576.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/2019Q1/cppWorkspace/leetcode576.cpp b/2019Q1/cppWorkspace/leetcode576.cpp index 8554d5d..ddb8df5 100644 --- a/2019Q1/cppWorkspace/leetcode576.cpp +++ b/2019Q1/cppWorkspace/leetcode576.cpp @@ -30,16 +30,16 @@ class Solution { return possiblePaths; auto toLeft{currentPos}; - toLeft.x--; + toLeft.y--; auto toRight{currentPos}; - toRight.x++; + toRight.y++; auto toUp{currentPos}; - toUp.y--; + toUp.x--; auto toDown{currentPos}; - toDown.y++; + toDown.x++; // Adding all the posibilities possiblePaths.emplace_back(toLeft); @@ -60,8 +60,7 @@ class Solution { } public: - int findPaths(int m, int n, int N, int i, int j) - { + int findPaths(int m, int n, int N, int i, int j) { auto retCount{0}; _boundary.first = m; _boundary.second = n; @@ -82,12 +81,17 @@ class Solution { _visitedMatrix[currentPos.x][currentPos.y] = true; // Get all the possible coordidate in which the in next move - currentPos.movesLeft--; - auto paths{getPossiblePaths(currentPos)}; + auto nextMove { currentPos }; + nextMove.movesLeft--; + auto paths{getPossiblePaths(nextMove)}; for (const auto &p : paths) { if (isOutside(p)) { - retCount += 1; + if( currentPos.movesLeft > 2 ) + retCount += 2; + else + retCount += 1; + retCount = retCount % (int)(pow(10,9) + 7); } else if( _visitedMatrix[p.x][p.y] == false ) {