본문 바로가기

열정가득한 개발자의 이야기/Javascript Algorithm

leetcode 575. Distribute Candies (javascript)

반응형

Hi! Happy New Year to you too!

 

I'm in Korea for a while to celebrate the Korean New Year with my family.

Even though I'm on holiday, I'm still studying algorithms to improve my logical thinking.

 

Anyway, this is what I'd solved.

 

Summary of My Solution:

This problem involves using arrays and the Set data structure to determine the maximum number of unique types.

Here's my approach:

  1. Initially, I solved the problem using an if statement, and it worked well.
  2. However, I wanted to make the code more concise, so I refactored it with a ternary operator. There was no significant difference in runtime between the if statement and the ternary operator.
  3. Personally, I prefer the ternary operator because it makes the code more compact and simple. I love writing code that's simple and readable.

 

Overall, I feel that I improved my logical thinking today.

Comparing my previous skills to my recent progress, I'm confident that my skills are improving.

 

Next, I'll aim to solve medium-level LeetCode problems as soon as possible.

 

 

반응형