From cd33ffc7b0c23494881ea67fc7f438969f759186 Mon Sep 17 00:00:00 2001 From: Mohammed Ebrahim <81110384+mohammed0xff@users.noreply.github.com> Date: Mon, 14 Nov 2022 22:50:20 +0200 Subject: [PATCH] Create WhereWilltheBallFall.cpp Add CPP solution for problem - "1706. Where Will the Ball Fall" -. --- .../WhereWilltheBallFall.cpp | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 algorithms/cpp/WhereWilltheBallFall/WhereWilltheBallFall.cpp diff --git a/algorithms/cpp/WhereWilltheBallFall/WhereWilltheBallFall.cpp b/algorithms/cpp/WhereWilltheBallFall/WhereWilltheBallFall.cpp new file mode 100644 index 00000000..1f920b16 --- /dev/null +++ b/algorithms/cpp/WhereWilltheBallFall/WhereWilltheBallFall.cpp @@ -0,0 +1,32 @@ +// https://leetcode.com/problems/where-will-the-ball-fall/ + +class Solution { +public: + vector findBall(vector>& grid) { + int N = grid.size(); + int M = grid[0].size(); + vector res; + + for(int ball=0;ball= M || j < 0) + break; + // if adjacent cell is closed (eg. going left and current is right) + if(cell != grid[i][j]) + break; + // go down one cell + i++; + } + // if got out safely. push column num ( j ) else push ( -1 ) + i == N ? res.push_back(j) : res.push_back(-1); + } + return res; + } +}; +