We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b9ea328 commit 8128f9fCopy full SHA for 8128f9f
489-robot-room-cleaner.js
@@ -63,3 +63,39 @@ const cleanRoom = function(robot) {
63
}
64
65
66
+
67
+// another
68
69
+/**
70
+ * @param {Robot} robot
71
+ * @return {void}
72
+ */
73
+const cleanRoom = function(robot) {
74
+ const dirs = [
75
+ [-1, 0],
76
+ [0, 1],
77
+ [1, 0],
78
+ [0, -1]
79
+ ]
80
+ const visited = new Set()
81
+ clean(0, 0, 0)
82
+ function clean( x, y, curDirection) {
83
+ robot.clean()
84
+ visited.add(`${x},${y}`)
85
+ for(let i = curDirection; i < curDirection + 4; i++) {
86
+ const nx = dirs[i % 4][0] + x
87
+ const ny = dirs[i % 4][1] + y
88
+ if(!visited.has(`${nx},${ny}`) && robot.move()) {
89
+ clean(nx, ny, i % 4)
90
+ }
91
+ robot.turnRight()
92
93
94
95
+ robot.move()
96
97
98
99
100
+};
101
0 commit comments