DEV Community

duccanhole
duccanhole

Posted on

4

code every day with me

--DAY 25--

Hi, I am going to make #100DaysOfCode Challenge. Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
Now let's solve problem today:
Problem: Utopian Tree
Detail: here
My solution (javascript):

function utopianTree(n) {
    let height = 1;
    if(n==0) return 1;
    for(let i=1;i<=n;i++){
        if(i%2!=0) height*=2;
        else height++;
    }
    return height;
}
Enter fullscreen mode Exit fullscreen mode

-->If you have better solution or any question, please comment below. I will appreciate.

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay