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

feat: add some other solutions #710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
KimYangOfCat wants to merge 1 commit into doocs:main from KimYangOfCat:kim
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: update solution of 189
  • Loading branch information
KimYangOfCat committed Feb 11, 2022
commit aa6f5b33eefcbf1a4bd2b6195c7faf3ffd84ec99
21 changes: 21 additions & 0 deletions solution/0100-0199/0189.Rotate Array/Solution.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,24 @@ var rotate = function (nums, k) {
k %= nums.length;
nums.splice(0, 0, ...nums.splice(-k, k));
};

/*
* Author: KimYangOfCat
*/
var rotate = function(nums, k) {
// 数组翻转想法
k%=nums.length;
reverse(nums,0,nums.length-1);
reverse(nums,0,k-1);
reverse(nums,k,nums.length-1);

};
function reverse(nums,start,end){
while(start<end){
const temp = nums[start];
nums[start]=nums[end];
nums[end]=temp;
start+=1;
end-=1;
}
}

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