leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 12b654c7aff45628bd062f355bb31f1ebf7ae5bc
parent c3c87694aba7a3eb60ac0287ed7d07b8548081b7
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Fri, 12 May 2023 12:05:44 -0500

Brute force solution to unique paths

Diffstat:
Aunique-paths/unique-paths.dart | 27+++++++++++++++++++++++++++
1 file changed, 27 insertions(+), 0 deletions(-)

diff --git a/unique-paths/unique-paths.dart b/unique-paths/unique-paths.dart @@ -0,0 +1,27 @@ +//Find all unique paths to reach the bottom right corner if you start at the top left. +//Return the total number of paths as an intgeer. This solution is 2^n time complexity +//and gives a TLE on leetcode. I will improve upon this in my next iteration. + +class Solution { + int uniquePaths(int m, int n) { + List<List<int>> queue = [[0,0]]; + int path_options = 0; + while(queue.length != 0){ + int i = queue.length - 1; + List<int> current = queue[i]; + queue.removeLast(); + if(current[0] < m){ + List<int> next = [current[0] + 1 , current[1]]; + queue.add(next); + } + if(current[1] < n - 1){ + List<int> next_val = [current[0] , current[1] + 1]; + queue.add(next_val); + } + if(current[0] == m-1 && current[1] == n-1){ + path_options += 1; + } + } + return path_options; + } +}