两行代码即可。

public class Solution {
  public int LastRemaining_Solution(int n, int m) {
    // 不满足的条件
    if (n <= 0 || m <= 0) return -1;
    return n == 1 ? 0 : (LastRemaining_Solution(n - 1, m) + m) % n;
  }
}