Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bc3bcf1

Browse files
Jian GUfishercoder1534
Jian GU
authored andcommitted
Update _189.java (#40)
1 parent 40e6a5c commit bc3bcf1

File tree

1 file changed

+14
-0
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+14
-0
lines changed

‎src/main/java/com/fishercoder/solutions/_189.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,18 @@ public static void rotate_naive(int[] nums, int k) {
7777
}
7878
}
7979
}
80+
81+
public static class Solution3 {
82+
public void rotate(int[] nums, int k) {
83+
int tmp = 0;
84+
for (int i = 0; i < k; i++) {
85+
tmp = nums[nums.length - 1];
86+
for (int j = nums.length - 1; j > 0; j--) {
87+
nums[j] = nums[j-1];
88+
}
89+
nums[0] = tmp;
90+
}
91+
}
92+
}
93+
8094
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /