C# solution


  • 0
    T
    public class Solution {
        public int FlipLights(int n, int m) {
            if(m == 0)
                return 1;
            if(n == 0)
                return 1;
            else if(n == 1)
                return 2;
            
            if(n > 4)
                n=4;
            
            HashSet<int> pool = new HashSet<int>();
            int max = 1 << n;
            pool.Add(max-1);
            int b1 = 15 >> (4-n);
            int b2 = 10 >> (4-n);
            int b3 = 5 >> (4-n);
            int b4 = 9 >> (4-n);
            while(m > 0 && pool.Count() < max){
                HashSet<int> newpool = new HashSet<int>();
                foreach(var item in pool){
                    newpool.Add(item ^ b1);
                    newpool.Add(item ^ b2);
                    newpool.Add(item ^ b3);
                    newpool.Add(item ^ b4);
                }
                pool = newpool;
                m--;
            }
            
            return pool.Count();
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.