diff --git "a/problems/0062.\344\270\215\345\220\214\350\267\257\345\276\204.md" "b/problems/0062.\344\270\215\345\220\214\350\267\257\345\276\204.md" index 5790df69ae..79e49b8773 100644 --- "a/problems/0062.\344\270\215\345\220\214\350\267\257\345\276\204.md" +++ "b/problems/0062.\344\270\215\345\220\214\350\267\257\345\276\204.md" @@ -452,5 +452,25 @@ object Solution { } ``` +### c# + +```c# +public class Solution +{ + public int UniquePaths(int m, int n) + { + int[] dp = new int[n]; + for (int i = 0; i < n; i++) + dp[i] = 1; + for (int i = 1; i < m; i++) + for (int j = 1; j < n; j++) + dp[j] += dp[j - 1]; + return dp[n - 1]; + } +} +``` + + + -----------------------
diff --git "a/problems/0070.\347\210\254\346\245\274\346\242\257.md" "b/problems/0070.\347\210\254\346\245\274\346\242\257.md" index 0a6acf7f69..903e8d589e 100644 --- "a/problems/0070.\347\210\254\346\245\274\346\242\257.md" +++ "b/problems/0070.\347\210\254\346\245\274\346\242\257.md" @@ -425,5 +425,25 @@ object Solution { } ``` +### C# + +```c# +public class Solution { + public int ClimbStairs(int n) { + if(n<=2) return n; + int[] dp = new int[2] { 1, 2 }; + for (int i = 3; i <= n; i++) + { + int temp = dp[0] + dp[1]; + dp[0] = dp[1]; + dp[1] = temp; + } + return dp[1]; + } +} +``` + + + -----------------------
diff --git "a/problems/0509.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260.md" "b/problems/0509.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260.md" index 0b53e69827..4c9317bcb4 100644 --- "a/problems/0509.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260.md" +++ "b/problems/0509.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260.md" @@ -370,5 +370,45 @@ object Solution { } ``` +### C# + +动态规划: + +```c# +public class Solution +{ + public int Fib(int n) + { + if(n<2) return n; + int[] dp = new int[2] { 0, 1 }; + for (int i = 2; i <= n; i++) + { + int temp = dp[0] + dp[1]; + dp[0] = dp[1]; + dp[1] = temp; + } + return dp[1]; + } +} +``` + +递归: + +```c# +public class Solution +{ + public int Fib(int n) + { + if(n<2) + return n; + return Fib(n-1)+Fib(n-2); + } +} +``` + + + + + -----------------------
diff --git "a/problems/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257.md" "b/problems/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257.md" index 9d3bd7fa20..4a4c0b6557 100644 --- "a/problems/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257.md" +++ "b/problems/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257.md" @@ -370,5 +370,26 @@ object Solution { } ``` +### C# + +```c# +public class Solution +{ + public int MinCostClimbingStairs(int[] cost) + { + int[] dp=new int[2] { cost[0], cost[1] }; + for (int i = 2; i < cost.Length; i++) + { + int temp = Math.Min(dp[0], dp[1])+cost[i]; + dp[0]=dp[1]; + dp[1]=temp; + } + return Math.Min(dp[0],dp[1]); + } +} +``` + + + -----------------------