public int UniquePaths(int m, int n) { HJPoint initalPoint = new HJPoint(0, n - 1); HJSize map = new HJSize(m, n); PointStack.Push(initalPoint); do { var curPoint = PointStack.Pop(); if (curPoint.X == map.Width - 1 && curPoint.Y == 0) { ++RouteCounts; continue; } var rightPoint = new HJPoint(curPoint.X + 1, curPoint.Y); var belowPoint = new HJPoint(curPoint.X, curPoint.Y - 1); if (map.Contains(rightPoint)) { PointStack.Push(rightPoint); } if (map.Contains(belowPoint)) { PointStack.Push(belowPoint); } } while (PointStack.Count != 0); return(RouteCounts); }
public bool Contains(HJPoint point) { if (point.X < Width && point.Y < Height && point.X >= 0 && point.Y >= 0) { return(true); } return(false); }