diff --git a/README.md b/README.md index 2bf93af3..fd3126b6 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,7 @@ LeetCode |1207|[Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences/) | [C++](./algorithms/cpp/uniqueNumberOfOccurrences/Unique-Number-of-Occurrences.cpp)|Easy| |1170|[Compare Strings by Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character/) | [C++](./algorithms/cpp/compareStringsByFrequencyOfTheSmallestCharacter/CompareStringsByFrequencyOfTheSmallestCharacter.cpp)|Easy| |1071|[Greatest Common Divisor of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings/) | [C++](./algorithms/cpp/greatestCommonDivisorOfStrings/GreatestCommonDivisorOfStrings.cpp)|Easy| +|1041|[Robot Bounded In Circle](https://leetcode.com/problems/robot-bounded-in-circle/description/) | [Python](./algorithms/python/RobotBoundedInCircle/RobotBoundedInCircle.py)|Medium| |1030|[Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order/) | [C++](./algorithms/cpp/matrixCellsInDistanceOrder/MatrixCellsInDistanceOrder.cpp)|Easy| |1029|[Two City Scheduling](https://leetcode.com/problems/two-city-scheduling/) | [C++](./algorithms/cpp/twoCityScheduling/TwoCityScheduling.cpp)|Easy| |1028|[Recover a Tree From Preorder Traversal](https://leetcode.com/problems/recover-a-tree-from-preorder-traversal/) | [C++](./algorithms/cpp/recoverATreeFromPreorderTraversal/recoverATreeFromPreorderTraversal.cpp)|Hard| diff --git a/algorithms/python/RobotBoundedInCircle/RobotBoundedInCircle.py b/algorithms/python/RobotBoundedInCircle/RobotBoundedInCircle.py new file mode 100644 index 00000000..e881b426 --- /dev/null +++ b/algorithms/python/RobotBoundedInCircle/RobotBoundedInCircle.py @@ -0,0 +1,17 @@ +class Solution(object): + def isRobotBounded(self, instructions): + """ + :type instructions: str + :rtype: bool + """ + dirx = 0 + diry = 1 + x = y = 0 + for ins in instructions: + if ins == "L": + dirx, diry = -1*diry, dirx + elif ins == "R": + dirx, diry = diry, -1*dirx + else: + x += dirx + y += diry