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

运行结果


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

相关推荐
lsylalalala12 小时前
常见的排序算法1
数据结构·算法·排序算法
想吃火锅100513 小时前
【leetcode】54. 螺旋矩阵
算法·leetcode·矩阵
wuminyu13 小时前
JVM利用io_uring优化堆外内存性能原理剖析
java·linux·c语言·jvm·c++
gumichef13 小时前
第二章:C/C++内存管理
c++·内存管理
想吃火锅100513 小时前
【leetcode】300. 最长递增子序列
算法·leetcode·职场和发展
imaol113 小时前
数据结构---队列
java·数据结构·算法
数模竞赛Paid answer13 小时前
2026年电工杯数学建模A题绿电直连型电氢氨园区优化运行求解全过程论文及程序
算法·数学建模·电工杯
疯狂打码的少年13 小时前
【数据结构】串的模式匹配:KMP算法(重点)
数据结构·笔记·算法
Dr.kangder14 小时前
嵌入式面试总结(八)——大小端
嵌入式硬件·面试·职场和发展·架构·嵌入式
晚风醉蝶14 小时前
第零篇-算法全景图
算法