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

运行结果


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

相关推荐
ZPC821013 小时前
docker 镜像备份
人工智能·算法·fpga开发·机器人
ZPC821013 小时前
docker 使用GUI ROS2
人工智能·算法·fpga开发·机器人
琢磨先生David13 小时前
Day1:基础入门·两数之和(LeetCode 1)
数据结构·算法·leetcode
哇哈哈202113 小时前
信号量和信号
linux·c++
颜酱13 小时前
栈的经典应用:从基础到进阶,解决LeetCode高频栈类问题
javascript·后端·算法
多恩Stone13 小时前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
生信大杂烩13 小时前
癌症中的“细胞邻域“:解码肿瘤微环境的空间密码 ——Nature Cancer 综述解读
人工智能·算法
蜡笔小马14 小时前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
一个人旅程~14 小时前
如何用命令行把win10/win11设置为长期暂停更新?
linux·windows·经验分享·电脑
m0_5312371714 小时前
C语言-数组练习进阶
c语言·开发语言·算法