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

运行结果


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

相关推荐
小小、码农4 分钟前
〖Linux文件系统〗:彻底打通文件 IO 全链路
linux·开发语言·数据结构·c++·系统
大侠归来7 分钟前
cJSON 源码解析:parse_string 函数深入剖析
linux·网络·算法
東隅已逝,桑榆非晚18 分钟前
priority_queue的介绍和使用
c++·经验分享·笔记·学习
茉莉玫瑰花茶35 分钟前
OpenGL [ 纹理 ]
开发语言·c++·opengl
余额瞒着我当琳1 小时前
C++ map 底层与AVL 树
开发语言·c++·算法
释厄6231 小时前
物理发展史·量子力学=节点2·牛顿力学=节点3·宇宙的语言算法AI
人工智能·算法·microsoft
CQU_JIAKE1 小时前
9.30【A】
算法
INGNIGHT2 小时前
1897 · 会议室 3(扫描线)
数据结构·算法
All for pursuit.2 小时前
【贪心-2】253.会议室 II
数据结构·c++·算法·leetcode
垆边人似月.2 小时前
华为机考题(一):质数因子
算法·华为