-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: master
Are you sure you want to change the base?
提交作业0926-hard -4 #12
Conversation
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++]); | ||
} | ||
} |
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.
这一段写的太复杂了,没必要再弄两个变量,直接两个循环就可以。
while (i < ken1){}
while (j < len2){}
由于这两个只会有一个被满足,所以不会有多余的运算。
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.
这一段写的太复杂了,没必要再弄两个变量,直接两个循环就可以。
while (i < ken1){}while (j < len2){}
由于这两个只会有一个被满足,所以不会有多余的运算。
好的黄总 我想一下
var findMedianSortedArrays = function (nums1, nums2){ | ||
let len1 = nums1.length; | ||
let len2 = nums2.length; | ||
let sum = len1 + len2; |
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.
这个变量命名不是很喜欢,可以用 length, length_sum,为啥要单用 sum...
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.
这个变量命名不是很喜欢,可以用 length, length_sum,为啥要单用 sum...
老子乐意
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 findMedianSortedArrays = function (nums1, nums2){ | ||
let nums = nums1.concat(nums2).sort((a,b)=>{return a-b}); | ||
nums1 = null;nums2 = null; |
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.
这里为啥要把 nums1 和 nums2 置空,有什么必要么?
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.
这里为啥要把 nums1 和 nums2 置空,有什么必要么?
没啥必要 就是想着手动释放内存
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.
去掉吧,没必要...理论上垃圾回收应该不会很差
* @param {number} numRows | ||
* @return {string} | ||
*/ | ||
var convert = function (s, numRows){ |
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.
写一下思路
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.
写一下思路
好的 黄总 我写下思路
} | ||
return res.join("") | ||
}; | ||
var convert1 = function convert(s, numRows){ |
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.
这个也写一下思路,不然代码太难懂了
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.
这个也写一下思路,不然代码太难懂了
好的黄总
r = i===0?0:i % (rows * 2); | ||
count=i===0?0:Math.floor(i / (rows * 2)); |
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.
这个是不是用一个 if 更好一些,可以少一次判断,且代码逻辑更加清晰
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.
这个是不是用一个 if 更好一些,可以少一次判断,且代码逻辑更加清晰
好的黄总
No description provided.