DEV Community

duccanhole
duccanhole

Posted on

code every day with me

--DAY 15--

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: Drawing Book
  • Detail: here
  • My solution (javascript):
function pageCount(n, p) {
    if(p==1||p==n||(p==n-1 && n%2!=0)) return 0;
    let move1=Math.floor(p/2);
    let move2=Math.floor(n/2)-move1;
    return Math.min(move1,move2);
}
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)