Leetcode—1232. 缀点成线【简单】

2024每日刷题(122)

Leetcode---1232. 缀点成线

算法思想

实现代码

cpp 复制代码
class Solution {
public:
    bool checkStraightLine(vector<vector<int>>& coordinates) {
        int x0 = coordinates[0][0];
        int y0 = coordinates[0][1];
        int x1 = coordinates[1][0];
        int y1 = coordinates[1][1];
        int dx = x1 - x0;
        int dy = y1 - y0;

        for(int i = 2; i < coordinates.size(); i++) {
            int x = coordinates[i][0];
            int y = coordinates[i][1];
            if((y - y0) * dx != (x - x0) * dy) {
                return false;
            }
        }
        return true;
    }
};

运行结果


之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!

相关推荐
菜鸟233号8 小时前
力扣377 组合总和 Ⅳ java实现
java·数据结构·算法·leetcode
我是大咖8 小时前
二级指针与指针数组搭配
c语言·数据结构·算法
是娇娇公主~8 小时前
工厂模式详细讲解
数据库·c++
老鼠只爱大米9 小时前
LeetCode算法题详解 189:轮转数组
leetcode·轮转数组·数组旋转·环状替换法·算法面试题
葫三生9 小时前
三生原理范畴语法表明中国哲学可为算法母语
人工智能·深度学习·算法·transformer
D_FW9 小时前
数据结构第五章:树与二叉树
数据结构·算法
WHS-_-20229 小时前
Tx and Rx IQ Imbalance Compensation for JCAS in 5G NR
javascript·算法·5g
_OP_CHEN9 小时前
【从零开始的Qt开发指南】(二十三)Qt 界面优化之 QSS 实战指南:从入门到精通,让你的界面颜值飙升!
开发语言·c++·qt·前端开发·界面美化·qss·客户端开发
HellowAmy9 小时前
我的C++规范 - 跳跃的对象
开发语言·c++·代码规范
jinmo_C++9 小时前
Leetcode_59. 螺旋矩阵 II
算法·leetcode·矩阵