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

运行结果


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

相关推荐
wordbaby29 分钟前
混合检索:两全其美的艺术
人工智能·算法
彧azz44 分钟前
数据结构:关于图的学习
c语言·数据结构·笔记·学习·算法
热心网友俣先生1 小时前
A题-药材的烘干问题-题意逐句翻译
算法·数学建模
2601_960356381 小时前
2026秋招运营分析师能力模型:SQL、指标体系、AIGC与业务分析
算法
hetao17338371 小时前
校内场-提高组 ZYZSC-S-Round 4
c++·算法
彧azz1 小时前
二叉搜索树学习记录
c语言·数据结构·笔记·算法
stellanke2 小时前
Linux网络编程实战2:TCP Socket 基础与实践
linux·网络·c++
手写码匠2 小时前
DeepSeek 函数调用实战:从零搭建一个会“动手“的 AI 助手
人工智能·深度学习·算法·aigc
蒸蒸yyyyzwd2 小时前
机试和Redis学习笔记
c++·笔记·面试
tdtsmt3 小时前
2026年SMT贴片加工选型指南:天地通电子推荐参考
c++