Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 22, 2021 02:50 am GMT

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To