Skip to content
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

提交作业0926-hard -4 #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

WangXinShu
Copy link
Collaborator

No description provided.

Comment on lines +37 to +47
let start = i, end = len1 - 1;
if (j < len2){
start = j, end = len2 - 1;
while (start <= end){
arr.push(nums2[start++]);
}
} else{
while (start <= end){
arr.push(nums1[start++]);
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一段写的太复杂了,没必要再弄两个变量,直接两个循环就可以。
while (i < ken1){}

while (j < len2){}

由于这两个只会有一个被满足,所以不会有多余的运算。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一段写的太复杂了,没必要再弄两个变量,直接两个循环就可以。
while (i < ken1){}

while (j < len2){}

由于这两个只会有一个被满足,所以不会有多余的运算。

好的黄总 我想一下

var findMedianSortedArrays = function (nums1, nums2){
let len1 = nums1.length;
let len2 = nums2.length;
let sum = len1 + len2;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个变量命名不是很喜欢,可以用 length, length_sum,为啥要单用 sum...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个变量命名不是很喜欢,可以用 length, length_sum,为啥要单用 sum...

老子乐意

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//排序
var findMedianSortedArrays = function (nums1, nums2){
let nums = nums1.concat(nums2).sort((a,b)=>{return a-b});
nums1 = null;nums2 = null;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为啥要把 nums1 和 nums2 置空,有什么必要么?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为啥要把 nums1 和 nums2 置空,有什么必要么?

没啥必要 就是想着手动释放内存

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去掉吧,没必要...理论上垃圾回收应该不会很差

* @param {number} numRows
* @return {string}
*/
var convert = function (s, numRows){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

写一下思路

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

写一下思路

好的 黄总 我写下思路

}
return res.join("")
};
var convert1 = function convert(s, numRows){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也写一下思路,不然代码太难懂了

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也写一下思路,不然代码太难懂了

好的黄总

Comment on lines +42 to +43
r = i===0?0:i % (rows * 2);
count=i===0?0:Math.floor(i / (rows * 2));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是不是用一个 if 更好一些,可以少一次判断,且代码逻辑更加清晰

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是不是用一个 if 更好一些,可以少一次判断,且代码逻辑更加清晰

好的黄总

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants