## Monday, August 8, 2016

[Solution]
backtracking题.

`  ``public` `List<String> timesWithNLights(``int` `n) {`
`    ``List<String> result = ``new` `ArrayList<>();`
`    ``if` `(n < ``0` `|| n > ``9``) {`
`      ``return` `result;`
`    ``}`
`    ``if` `(n == ``0``) {`
`      ``result.add(``"0:0"``);`
`      ``return` `result;`
`    ``}`

`    ``int``[] clock = ``new` `int``[``11``];`
`    ``backtracking(clock, n, ``0``, result);`
`    ``return` `result;`
`  ``}`

`  ``private` `void` `backtracking(``int``[] clock, ``int` `n, ``int` `pos, List<String> result) {`
`    ``if` `(n == ``0``) {`
`      ``int` `h = ``0``;`
`      ``int` `m = ``0``;`
`      ``for` `(``int` `i = ``10``; i >= ``0``; i--) {`
`        ``if` `(i > ``4` `&& clock[i] == ``1``) {`
`          ``m += (``1` `<< (``10` `- i));`
`        ``}`
`        ``if` `(i <= ``4` `&& clock[i] == ``1``) {`
`          ``h += (``1` `<< (``4` `- i));`
`        ``}`
`      ``}`
`      ``if` `(h <= ``23` `&& m <= ``59``) {`
`        ``result.add(String.valueOf(h) + ``":"` `+ String.valueOf(m));`
`      ``}`
`      ``return``;`
`    ``}`

`    ``int` `i = pos;`
`    ``while` `(i < clock.length) {`
`      ``clock[i] = ``1``;`
`      ``n--;`
`      ``backtracking(clock, n, i + ``1``, result);`
`      ``n++;`
`      ``clock[i] = ``0``;`
`      ``i++;`
`    ``}`
`  ``}`