leetCode 62(unique paths):
A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’ in the diagram below). How many possible unique paths are there?
solution: it’s easy to model as a math combination problem, assume the right-step has m; the down-step has n. so each path from top left to bottom right, has (m+n) steps totally. the total unique paths is C_(m+n)^m
passing by value:
|
|
what happened if rm-1 changed to rm–?
warning: unsequenced modification and access to 'rm'
what about passing as reference ?
|
|
if using m– :
error: expects an l-value for 1st argument of sol(int&, int&)
m– is only r-value, can’t be used as reference varaible; but –m is r-value.
for m as a reference variable, –m is the way to update the content of the address. while m– more like move to the next address?