Leetcode—1232. 缀点成线【简单】

2024每日刷题(122)

Leetcode—1232. 缀点成线

在这里插入图片描述

算法思想

在这里插入图片描述

实现代码

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

运行结果

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

相关推荐

  1. leetcode题目122

    2024-05-01 18:32:02       33 阅读
  2. LeetCode //C - 1732. Find the Highest Altitude

    2024-05-01 18:32:02       51 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-01 18:32:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-01 18:32:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-05-01 18:32:02       87 阅读
  4. Python语言-面向对象

    2024-05-01 18:32:02       96 阅读

热门阅读

  1. 学习mysql相关知识记录

    2024-05-01 18:32:02       33 阅读
  2. 大模型LoRA微调调参的实战技巧

    2024-05-01 18:32:02       36 阅读
  3. 在编程中,方法和函数都是什么意思

    2024-05-01 18:32:02       33 阅读
  4. C语言创建文件夹和多级目录

    2024-05-01 18:32:02       33 阅读
  5. DB-GPT源码阅读1-数据库表读取

    2024-05-01 18:32:02       32 阅读
  6. 2024 c/c++A组填空第一题--选择与篮球

    2024-05-01 18:32:02       30 阅读
  7. 网络安全思考题

    2024-05-01 18:32:02       35 阅读
  8. 自动化测试——Selenium

    2024-05-01 18:32:02       32 阅读
  9. C++临时对象的产生及优化

    2024-05-01 18:32:02       23 阅读