An Interest In:
Web News this Week
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
October 22, 2021 02:50 am GMT
Original Link: https://dev.to/coderduck/code-every-day-with-me-2kmi
code every day with me
--DAY 4--
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: Longest Common Prefix
-Detail: https://leetcode.com/problems/longest-common-prefix/
-My solution (javascript):
var longestCommonPrefix = function(str) { if(str.length==0) return ''; let prefix=''; for(let i=0;i<str[0].length;i++){ let check=true; for(let j=1;j<str.length;j++){ if(str[j].charAt(i)!=str[0].charAt(i)){ return prefix; } } if(check) prefix+=str[0].charAt(i); } return prefix;};
-->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-2kmi
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