[Java] Leetcode 1041. Robot Bounded In Circle [Array #10]

  Рет қаралды 3,346

Eric Programming

Eric Programming

Күн бұрын

Пікірлер: 2
@Wjdveiwlslfbeb
@Wjdveiwlslfbeb 2 жыл бұрын
thank you so much! very clear and easy solution!
@jeroenvandenheuvel3869
@jeroenvandenheuvel3869 2 жыл бұрын
Thanks for the explanation! Although this solution works well it's a bit more complex than necessary. What about using cosine and sine? ``` x = 0 y = 0 rotation = 0 for instruction in instructions: if instruction == "L": rotation += 270 rotation = rotation % 360 elif instruction == "R": rotation += 90 rotation = rotation % 360 else: y -= int(math.cos(math.radians(rotation))) x += int(math.sin(math.radians(rotation))) if x == 0 and y == 0: return True elif rotation != 0: return True return False ``` Or without these functions the movement can be done like this: ``` if rotation % 180 == 0: y += (rotation / 90) - 1 else: x -= (rotation / 90) - 2 ```
[Java] Leetcode 31. Next Permutation [Array #11]
11:58
Eric Programming
Рет қаралды 3,1 М.
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 11 МЛН
Yay😃 Let's make a Cute Handbag for me 👜 #diycrafts #shorts
00:33
LearnToon - Learn & Play
Рет қаралды 117 МЛН
Robot Bounded In Circle 🔥| Leetcode 1041 | Math | String
18:02
Ayushi Sharma
Рет қаралды 3,9 М.
5 Steps to Problem Solve Coding Interview Questions
14:10
Eric Programming
Рет қаралды 3,7 М.
⚡️NEWS | RUBLE COLLAPSE | STRIKE ON CRIMEA | PUTIN IN KAZAKHSTAN
10:34
Ходорковский LIVE
Рет қаралды 184 М.
Robot Bounded In Circle
14:20
layman coding
Рет қаралды 4,7 М.
[Java] Leetcode 279. Perfect Squares [DP Integer Partition #2]
11:08
Eric Programming
Рет қаралды 2,3 М.