1 class Solution { 2 public: 3 int lastRemaining(int n, int m) { 4 if(n==1)return 0; 5 return (m%n+lastRemaining(n-1,m))%n;//以m%n为参考系,当成0,求得n-1的解再换系;也不用m%n主要是为了理解; 6 } 7 };
2023-11-08 23:07:22
1 class Solution { 2 public: 3 int lastRemaining(int n, int m) { 4 if(n==1)return 0; 5 return (m%n+lastRemaining(n-1,m))%n;//以m%n为参考系,当成0,求得n-1的解再换系;也不用m%n主要是为了理解; 6 } 7 };