-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
feat: add a JS solution of 189 #712
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
明白了,抱歉 |
代码的格式也需要调整,比如这段代码: 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);
}; 需要改成: 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);
}; 空格,缩进等。 |
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | |
} | |
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; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也需要改一下哈 @KimYangOfCat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README_EN.md 同
已合并,感谢参与项目,期待你更多的 pr 哈 |
很少手动格式化代码(使用工具居多),对很多代码格式不太熟悉,抱歉,给你添麻烦了, 感谢你的指导,基本清楚了需要注意的地方,后续会注意哒, 不过感觉这样手动格式化代码,你们的校对工作量好大呀,辛苦了! 有空的时候,我可以研究一下是否可以使用CLI的方式自动格式化代码,方便减轻你们的工作量 |
可以配置 github actions 自动格式化代码,不过会产生新的 commit。 我目前倾向于每个人提交代码的时候,自己保证代码格式是 ok 的。 |
那真是辛苦了,感谢你的付出,点赞 |
对于格式化,项目中添加了 prettier,大多数 IDE 都集成了配套插件。 |
是的,项目中有 prettier 相关配置,可以统一格式。 只需要在 VSCode 等编辑器中安装 prettier 插件进行格式化即可。 |
参考 #710 的意见,重新提交,请不吝指出任何不规范之处