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