C# DP solution, Bottom up


  • 0
    H

    public class Solution {
    public IList<int> GrayCode(int n) {

      List<int> res = new List<int>();
      res.Add(0);
      if( n == 0) return res;
      
      for(int i = 1; i <= n; i++){
          for( int j = res.Count-1; j >= 0; j--){
              res.Add( 1<<(i-1)|res[j] );
          }
      }
      
      return res;
      
    }
    

    }


Log in to reply
 

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