第一百零一天:力扣 1232题,缀点成线
地址:leetcode-cn.com/problems/ch…
思路:数学题,意义不大
var checkStraightLine = function(coordinates) {
const deltaX = coordinates[0][0], deltaY = coordinates[0][1];
const n = coordinates.length;
for (let i = 0; i < n; i++) {
coordinates[i][0] -= deltaX;
coordinates[i][1] -= deltaY;
}
const A = coordinates[1][1], B = -coordinates[1][0];
for (let i = 2; i < n; i++) {
const [x, y] = [coordinates[i][0], coordinates[i][1]];
if (A * x + B * y !== 0) {
return false;
}
}
return true;
};
执行用时:76 ms, 在所有 JavaScript 提交中击败了96.64%的用户
内存消耗:39.5 MB, 在所有 JavaScript 提交中击败了41.18%的用户