Google电面题 写dominoChecker class# JobHunting - 待字闺中
h*p
1 楼
Write a class DominoChecker that has a method called addBox(int[]) that
takes a box of five dominoes,
described as a list of 10 integers (explained after), adds it to a
collection,
and returns true if a box with the same dominoes was already in the
collection and false otherwise.
A box of dominoes is encoded as a list of 10 integers from 0 to 9, where a
pair of numbers represent a domino.
For example: 0,2,9,1,3,3,7,4,5,6 represents a box containing dominoes: (0,2)
; (9,1); (3,3); (7,4); (5,6).
注意: (1)对于domino(0,2)和(2,0)是一样的.
(2) addBox的时候需要track以前添加的box
DominoChecker checker = new DominoChecker(???? up to you ???);
checker.addBox("1234567811"); // returns false
checker.addBox("1233445566"); // returns false
checker.addBox("1233445566"); // returns true;
checker.addBox("3344556612"); // returns true;
checker.addBox("3344556621"); // returns true;
请教大家有什么好的思路
takes a box of five dominoes,
described as a list of 10 integers (explained after), adds it to a
collection,
and returns true if a box with the same dominoes was already in the
collection and false otherwise.
A box of dominoes is encoded as a list of 10 integers from 0 to 9, where a
pair of numbers represent a domino.
For example: 0,2,9,1,3,3,7,4,5,6 represents a box containing dominoes: (0,2)
; (9,1); (3,3); (7,4); (5,6).
注意: (1)对于domino(0,2)和(2,0)是一样的.
(2) addBox的时候需要track以前添加的box
DominoChecker checker = new DominoChecker(???? up to you ???);
checker.addBox("1234567811"); // returns false
checker.addBox("1233445566"); // returns false
checker.addBox("1233445566"); // returns true;
checker.addBox("3344556612"); // returns true;
checker.addBox("3344556621"); // returns true;
请教大家有什么好的思路