Re: [闲聊] 每日LeetCode

楼主: Che31128 (justjoke)   2023-06-05 14:09:23
https://leetcode.com/problems/check-if-it-is-a-straight-line/description/
1232. Check If It Is a Straight Line
给一个阵列coordinates[i][j],coordinates[i]为第i+1个点,j=0为x轴
j=1为y轴,判断这几个点是否连成一线。
Example 1:
https://assets.leetcode.com/uploads/2019/10/15/untitled-diagram-2.jpg
Input: coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]
Output: true
Example 2:
https://assets.leetcode.com/uploads/2019/10/09/untitled-diagram-1.jpg
Input: coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]
Output: false
思路:
1.找出第一个点与第二点的斜率,依序寻找每一点斜率是否相等。
2.为防止runtime error用乘法来判断。
java code
作者: SecondRun (雨夜琴声)   2023-06-05 14:12:00
大师
作者: sustainer123 (caster)   2023-06-05 14:26:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com