Google 面试题 灯泡状态


You have a system with N light bulbs indexed from 0 to N1. The light bulbs are all in an OFF state. The system allows you to perform two operations: * boolean isOn(int index) return true if light bulb at given index is ON, false otherwise.
* void toggle(int start, int end) toggle all the light bulbs in the range [start, end] (inclusive). So if the light was ON in that range, flip it to OFF, and if it was OFF > to ON.

Implement the class that allows me to efficiently use the two given methods

据说用线段树解,真心不知道怎么写。
已邀请:

luluxiu

赞同来自:


interval tree入门题

要回复问题请先登录注册