unique-paths.dart (960B)
1 //Find all unique paths to reach the bottom right corner if you start at the top left. 2 //Return the total number of paths as an intgeer. This solution is 2^n time complexity 3 //and gives a TLE on leetcode. I will improve upon this in my next iteration. 4 5 class Solution { 6 int uniquePaths(int m, int n) { 7 List<List<int>> queue = [[0,0]]; 8 int path_options = 0; 9 while(queue.length != 0){ 10 int i = queue.length - 1; 11 List<int> current = queue[i]; 12 queue.removeLast(); 13 if(current[0] < m){ 14 List<int> next = [current[0] + 1 , current[1]]; 15 queue.add(next); 16 } 17 if(current[1] < n - 1){ 18 List<int> next_val = [current[0] , current[1] + 1]; 19 queue.add(next_val); 20 } 21 if(current[0] == m-1 && current[1] == n-1){ 22 path_options += 1; 23 } 24 } 25 return path_options; 26 } 27 }