Skip to content

1006. Clumsy Factorial 👎

  • Time:
  • Space:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
 public:
  int clumsy(int N) {
    if (N == 1)
      return 1;
    if (N == 2)
      return 2;
    if (N == 3)
      return 6;
    if (N == 4)
      return 7;
    if (N % 4 == 1)
      return N + 2;
    if (N % 4 == 2)
      return N + 2;
    if (N % 4 == 3)
      return N - 1;
    return N + 1;
  }
};
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
class Solution {
  public int clumsy(int N) {
    if (N == 1)
      return 1;
    if (N == 2)
      return 2;
    if (N == 3)
      return 6;
    if (N == 4)
      return 7;
    if (N % 4 == 1)
      return N + 2;
    if (N % 4 == 2)
      return N + 2;
    if (N % 4 == 3)
      return N - 1;
    return N + 1;
  }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Solution:
  def clumsy(self, N: int) -> int:
    if N == 1:
      return 1
    if N == 2:
      return 2
    if N == 3:
      return 6
    if N == 4:
      return 7
    if N % 4 == 1:
      return N + 2
    if N % 4 == 2:
      return N + 2
    if N % 4 == 3:
      return N - 1
    return N + 1
Back to top