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

运行结果


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

相关推荐
员工风险管理实务13 分钟前
职务侵占有什么价值?岗位关联性与必要性判断
职场和发展
sysu_chenxy1 小时前
二重循环输出二维图形
c++
Navigator_Z1 小时前
LeetCode //C - 1293. Shortest Path in a Grid with Obstacles Elimination
c语言·算法·leetcode
每天get到一点新知识2 小时前
7款电脑数据恢复软件集合!恢复硬盘数据,其实很简单!
经验分享·电脑·数据恢复·电脑知识·电脑小技巧
Nil2082 小时前
leetcode 64最小路径和
算法·leetcode·职场和发展
光影少年2 小时前
AI Agent、自动化与未来工作
人工智能·算法·架构
腾科IT教育2 小时前
HCIE-Datacom通关经验分享 - 毕业一年网工备考心得
网络·经验分享·学习方法·华为认证·hcie·数通
牧羊人.3332 小时前
计算机视觉基础 第16章|EigenFace,FisherFace,LBPH传统人脸识别算法
人工智能·算法·计算机视觉
考研保研资料分享2 小时前
双非新闻学保研复盘:东华小组展示、长安面试与兰大预推免
面试·职场和发展
Nil2082 小时前
leetcode 72编辑距离
算法·leetcode·职场和发展