You are viewing a single comment's thread. Return to all comments →
solution 1: O(1) cpp solution--
int utopianTree(int n) { int exponent=n/2 +1 +n%2; int result=pow(2,exponent); if(n%2==0){ return result-1; } else{ return result-2; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Utopian Tree
You are viewing a single comment's thread. Return to all comments →
solution 1: O(1) cpp solution--
int utopianTree(int n) { int exponent=n/2 +1 +n%2; int result=pow(2,exponent); if(n%2==0){ return result-1; } else{ return result-2; } }