Advertisement
HXXXXJ

Get Path "R+D"

Mar 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.43 KB | None | 0 0
  1. func getPath(_ n : Int) -> Set<String>{
  2.     var res = Set<String>()
  3.     getPathDFS(n , n , "", &res)
  4.    
  5.     return res
  6. }
  7.  
  8.  
  9. func getPathDFS(_ n : Int, _ m : Int, _ curr: String, _ res: inout  Set<String>){
  10.     if n == 0 && m == 0{
  11.         res.insert(curr)
  12.         return
  13.     }
  14.     if n > 0 {
  15.         getPathDFS( n - 1, m, curr + "d", &res)
  16.     }
  17.     if m > 0 {
  18.         getPathDFS( n , m - 1, curr + "r", &res)
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement