An Interest In:
Web News this Week
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
October 23, 2021 04:13 am GMT
Original Link: https://dev.to/coderduck/code-every-day-with-me-28ag
code every day with me
--DAY 5--
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: Number Line Jumps
-Detail: https://www.hackerrank.com/challenges/kangaroo/problem
-My solution (javascript):
function kangaroo(x1, v1, x2, v2) { while(x1 >= 0){ //if they in same position if(x1==x2) return 'YES'; //caculate the distance of 2 kangaroo let distance = Math.abs(x1-x2); //kangaroo 1 move x1+=v1; //kangaroo 2 move x2+=v2; //if the distance between 2 kangaroo longer or no change, they will never meet if(Math.abs(x1-x2)>=distance) return 'NO'; }}
-->If you have better solution or any question, please comment below. I will appreciate.
Original Link: https://dev.to/coderduck/code-every-day-with-me-28ag
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To