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

运行结果


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

相关推荐
zhurui_xiaozhuzaizai16 分钟前
模型训练-关于token【低概率token, 高熵token】
人工智能·算法·自然语言处理
ThreeYear_s22 分钟前
基于FPGA的PID算法学习———实现PID比例控制算法
学习·算法·fpga开发
tkevinjd1 小时前
C++中线程库的基本操作
开发语言·c++
CodeWithMe1 小时前
【C/C++】不同防止头文件重复包含的措施
c语言·开发语言·c++
Fre丸子_1 小时前
C++定长内存块的实现
c++
子豪-中国机器人1 小时前
C++ 信息学奥赛总复习题答案解析
开发语言·c++·算法
弥彦_2 小时前
牛客round95D
c++·算法
oioihoii2 小时前
C++11列表初始化:从入门到精通
java·开发语言·c++
tomato092 小时前
2025 年中国大学生程序设计竞赛全国邀请赛(郑州)暨第七届CCPC河南省大学生程序设计竞赛(补题)
c++
whoarethenext2 小时前
使用 C++/OpenCV 创建动态流星雨特效 (实时动画)
开发语言·c++·opencv