14. Longest Common Prefix

Topics:

Problem Description

Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string "".

Example 1:

    Input: strs = ["flower","flow","flight"]"
    Output: "fl"
    

Example 2:

    Input: strs = ["dog","racecar","car"]
    Output: ""
    Explanation: There is no common prefix among the input strings.
    

Constraints:

  
    1 <= strs.length <= 200
    0 <= strs[i].length <= 200
    strs[i] consists of only lowercase English letters.

Solution

C#


      public void AddFirst(Node newNode)
        {
            if (this.First == null) //if the list is empty
            {
                //insert the new node and point the head and tail to the node
                this.First = newNode;  
                this.Last = newNode;  
            }
            else
            {
                newNode.Next = this.First;
                this.First = newNode;
            }
            Count++;
        }

    
Link to demo with User Interface

JavaScript


        function addSum(int1, int2){
          let result = int1 + int2;
          return result;
        }
      

Complexity Analysis