Data Structure & Algorithm: Level-1 Problem #46. Crossroads

Given a list of moving directions, among them 0° stands for east, 180° for west, 90° for north and 270° for south. The starting point is the

Given a list of integers for moving directions,0°, 90°, 180° and 270°, each representing moving one unit east, north, west or south respectively. The starting point is (0, 0) for a plane coordinates system. Check whether there is a crossroads with the moving records.

Sample Input:

[0, 270, 270, 180, 90, 90]

Sample Output:

True

The moving records in the sample will form a crossroad at position (0, 0).

crossroads

数据结构和算法:初级练习题 #46 – 交叉路口

给定一组数字代表移动的方向,每个数字都是0°、90°、180°、270° 中的一个,分别表示向东、北、西或南移动一格。起始位置位于二维平面坐标的原点(0,0),检查移动的轨迹是否会形成交叉路口。

输入样例:

[0, 270, 270, 180, 90, 90]

输出样例:

True

输入样例里的移动轨迹会在原点形成交叉,如上图所示。

Python Solution

Crossroads