Skip to content

Instantly share code, notes, and snippets.

@yuessir
Created October 18, 2022 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuessir/38a1f858eb092465722f8dab347862cd to your computer and use it in GitHub Desktop.
Save yuessir/38a1f858eb092465722f8dab347862cd to your computer and use it in GitHub Desktop.
print leet code 70 all sooutions
/// <summary>
/// Gets up stairs path.
/// </summary>
/// <param name="res">結果集合.</param>
/// <param name="path">The path.</param>
/// <param name="totalStairs">樓梯總數.</param>
/// <param name="stepMethod">可能的步進階數.</param>
/// <returns></returns>
private static List<List<int>> GetUpStairsPath(List<List<int>> result, List<int> goThroughPath, int totalStairs,int[] stepMethod)
{
if (totalStairs == 0)
{
var path = new List<int>();
path.AddRange(goThroughPath);
result.Add(path);
return result;
}
for (int i = 0; i < stepMethod.Length; i++)
{
if (totalStairs >= stepMethod[i])
{
goThroughPath.Add(stepMethod[i]);
GetUpStairsPath(result, goThroughPath, totalStairs - stepMethod[i], stepMethod);
goThroughPath.RemoveAt(goThroughPath.Count-1);
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment