일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 프로젝트
- 미드시청
- FIT XR
- Daily Challenge
- 3줄정리
- 읽기
- 매일
- 영어원서읽기
- 잡생각
- 30분
- leetcode
- realclass
- 스탭퍼
- 월간
- 쓰릴오브파이트
- English
- 만화도
- 10분
- 사이드
- Problem Solving
- 화상영어
- 개발자
- 리얼 클래스
- 운동
- 파비최
- 영어공부
- 링피트
- 뭐든
- 괜찮음
- Writing
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.06.05 Today's Challenge 본문
https://leetcode.com/problems/check-if-it-is-a-straight-line/
Check If It Is a Straight Line - LeetCode
Can you solve this real interview question? Check If It Is a Straight Line - You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane.
leetcode.com
오랫만에 직접 풀기 시도했는데, divided by zero 때문에 실패 계속 뜸 ㅠㅠ
class Solution:
def checkStraightLine(self, coordinates: List[List[int]]) -> bool:
coordinates.sort(key=lambda x: (x[0], x[1]))
fir, sec = coordinates[0], coordinates[1]
for i in range(2, len(coordinates)):
c = coordinates[i]
if (c[0] - fir[0]) * (sec[1] - fir[1]) != (c[1] - fir[1]) * (sec[0] - fir[0]):
return False
return True
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.06.07 Today's Challenge (0) | 2023.06.07 |
---|---|
2023.06.06 Today's Challenge (0) | 2023.06.06 |
2023.06.04 Today's Challenge (0) | 2023.06.04 |
2023.06.03 Today's Challenge (0) | 2023.06.03 |
2023.06.02 Today's Challenge (0) | 2023.06.02 |
Comments