Quick actions

cmd+k|ctrl+k

Navigation

Languages

Udemy: Master Coding Interview - Big O - #26

Snippet info

Language

Csharp

Visibility

public

Author

jcurrie33

Created

2020-07-31T23:33:17Z

Updated

2020-07-31T23:59:27Z

using System;
using System.Diagnostics;

class MainClass {
    static string[] nemo = {"nemo"};
    static string[] everyone = {"dory", "bruce", "marlin", "nemo", "gill", 
    "bloat", "nigel", "squirt", "darla", "hank"};
    static string[] large;
    static string[] larger;
    static string[] largest;
    
    static void Main() {
        large = new string[100];
        Array.Fill(large, "nemo");
        larger = new string[100000];
        Array.Fill(larger, "nemo");
        largest = new string[10000000];
        Array.Fill(largest, "nemo");
        
        MainClass.findNemo(nemo);
        MainClass.findNemo(everyone);
        MainClass.findNemo(large);
        MainClass.findNemo(larger);
        MainClass.findNemo(largest);
    }
    
    public static void findNemo(string[] array) {
        Stopwatch sw = new Stopwatch();
        sw.Start();
        for (int i = 0; i < array.Length; i++) {
            if (array[i] == "nemo") {
                //Console.WriteLine("Found NEMO!");
            }
        }
        sw.Stop();
        Console.WriteLine("Call to findNemo() took {0}", sw.Elapsed);
    }
}
INFO