Created
October 18, 2022 09:19
-
-
Save yuessir/38a1f858eb092465722f8dab347862cd to your computer and use it in GitHub Desktop.
print leet code 70 all sooutions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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