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

运行结果


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

相关推荐
hPw0eKIqD4 小时前
C++ 模板参数推导问题小记(非推导上下文)
开发语言·c++
程序员爱德华5 小时前
Python与C++:异同点对比
c++·python
普通攻击往后拉5 小时前
Leetcode 206. 反转链表
算法·leetcode·链表
@syh.6 小时前
【贪心】矩阵消除游戏
算法·游戏·矩阵
可编程芯片开发6 小时前
基于零极点配置的PID控制系统simulink建模与仿真
算法
徐小夕7 小时前
开源!我用SQLite + DuckDB打造了一款可视化AI问数平台
前端·算法·github
Hrain-AI7 小时前
2026 企业 AI 智能体平台横评:8 大主流平台 7 维度实测对比
人工智能·算法·机器学习
Angel Q.8 小时前
因子分析和生成模型有什么关系?从“幕后因素”到“生成数据”
算法
888CC++8 小时前
C语言与C++的区别:从面向过程到面向对象
java·c语言·c++