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

运行结果


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

相关推荐
Mr YiRan5 小时前
C++面向对象继承与操作符重载
开发语言·c++·算法
香芋Yu9 小时前
【大模型面试突击】10_推理部署与优化
面试·职场和发展
蚊子码农9 小时前
算法题解记录--239滑动窗口最大值
数据结构·算法
liliangcsdn9 小时前
A3C算法从目标函数到梯度策略的探索
算法
陈天伟教授10 小时前
人工智能应用- 材料微观:06.GAN 三维重构
人工智能·神经网络·算法·机器学习·重构·推荐算法
liliangcsdn10 小时前
A3C强化学习算法的探索和学习
算法
Figo_Cheung11 小时前
Figo《量子几何学:从希尔伯特空间到全息时空的统一理论体系》(二)
算法·机器学习·几何学·量子计算
额,不知道写啥。11 小时前
HAO的线段树(中(上))
数据结构·c++·算法
LYS_061811 小时前
C++学习(5)(函数 指针 引用)
java·c++·算法
紫陌涵光11 小时前
669. 修剪二叉搜索树
算法·leetcode