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;
    }
};

运行结果


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

相关推荐
东莞呵呵5 分钟前
吴恩达机器学习(1)——机器学习算法分类
算法·机器学习·分类
虾球xz9 分钟前
游戏引擎学习第293天:移动Familiars
c++·学习·游戏引擎
孙同学_24 分钟前
【C++】map和set的使用
开发语言·c++
wjm04100639 分钟前
C++中的容器
开发语言·c++
赵谨言2 小时前
基于单片机的防盗报警器设计与实现
经验分享·单片机·毕业设计
脚大江山稳2 小时前
二进制与十进制互转的方法
c++
Dovis(誓平步青云)3 小时前
“Cloud Native English“云原生时代下的微服务架构设计:从理论到实战全解析
经验分享·微服务·云原生·架构
远瞻。4 小时前
【论文阅读】人脸修复(face restoration ) 不同先验代表算法整理2
论文阅读·算法
先做个垃圾出来………7 小时前
哈夫曼树(Huffman Tree)
数据结构·算法
醍醐三叶8 小时前
C++类与对象--2 对象的初始化和清理
开发语言·c++