programming challenge – LeetCode: Replace Words Trie C #

I'm trying to solve this leet code problem
https://leetcode.com/problems/replace-words/

Please comment on the performance.

In English, we have a concept called root, which can be followed by
some other words to form another longer word – let's call this word
successor. For example, the root one, followed by another, which can form
another word another.

Now, given a dictionary that consists of many roots and a sentence. Your
I need to replace all the successor in the sentence with the root.
forming it If a successor has many roots he can form it, replace it with
The root with the shortest length.

It is necessary to give out the prayer after the replacement.

Example 1:

Entry: dict = ["cat", "bat", "rat"]
phrase = "the cattle was shaken by the battery"
Output: "The cat was rat by the bat."

Note:

The entry will only have lowercase letters. 1 <= dict words number <=
1000 1 <= number of words in the sentence <= 1000 1 <= length of the root <= 100 1 <=
length of the words in the sentence <= 1000

using the system;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Security.Policy;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TrieQuestions
{
    [TestClass]
    public class TrieReplaceWords
{
        [TestMethod]
        Public void ReplaceWordsTest ()
{
List dict = new list {"cat", "bat", "rat"};
const string string = "the cattle was rocked by the battery";
const string output = "the cat was rat for the bat";
Assert.AreEqual (output, ReplaceWords (dict, sentence));
}

        [TestMethod]
        public empty LeetCodeLongTest ()
{
List dict = new list {
"e", "k", "c", "harqp", "h", "gsafc", "vn", "lqp", "am", "mr", "x", "iitgm", "sb "," oo "," spj "," gwmly "," iu "," z "," f "," ha "," vds "," v "," vpx "," fir "," t ", "xo", "apifm", "tlznm", "kkv", "nxyud", "j", "qp", "omn", "zoxp", "mutu", "i", "nxth", "dwuer "," sadl "," pv "," w "," mding "," mubem "," xsmwc "," vl "," farov "," twfmq "," ljhmr "," q "," bbzs ", "kd", "kwc", "a", "buq", "sm", "yi", "nypa", "xwz", "yes", "amqx", "iy", "eb", "qvgt "," twy "," rf "," dc "," utt "," mxjfu "," hm "," trz "," lzh "," lref "," qbx "," fmemr "," gil ", "go", "qggh", "uud", "trnhf", "gels", "dfdq", "qzkx", "qxw"};
sentence const string = "ikkbp miszkays wqjferqoxjwvbieyk gvcfldkiavww vhokchxz dvypwyb bxahfzcfanteibiltins ueebf lqhflvwxksi DCO kddxmckhvqifbuzkhstp wc ytzzlm gximjuhzfdjuamhsu gdkbmhpnvy ifvifheoxqlbosfww mengfdydekwttkhbzenk wjhmmyltmeufqvcpcxg hthcuovils ldipovluo aiprogn nusquzpmnogtjkklfhta klxvvlvyh nxzgnrveghc mpppfhzjkbucv cqcft uwmahhqradjtf iaaasabqqzmbcig zcpvpyypsmodtoiif qjuiqtfhzcpnmtk yzfragcextvx ivnvgkaqs iplazv jurtsyh gzixfeugj rnukjgtjpim hscyhgoru aledyrmzwhsz xbahcwfwm HZD ygelddphxnbh rvjxtlqfnlmwdoezh zawfkko iwhkcddxgpqtdrjrcv bbfj MHS nenrqfkbf spfpazr wrkjiwyf cw dtd cqibzmuuhukwylrnld dtaxhddidfwqs bgnnoxgyynol hg dijhrrpnwjlju muzzrrsypzgwvblf zbugltrnyzbg hktdviastoireyiqf qvufxgcixvhrjqtna ipfzhuvgo DAEE r nlipyfszvxlwqw yoq dewpgtcrzausqwhh qzsaobsghgm ichlpsjlsrwzhbyfhm ksenb bqprarpgnyemzwifqzz oai pnqottd nygesjtlpala qmxixtooxtbrzyorn gyvukjpc s mxhlkdaycskj uvwmerplaibeknltuvd ocnn frotscysdyclrc ckcttaceuuxzcghw pxbd oklwhcppuziixpvihihp ";
string output const = "i miszkays w gvcfldkiavww v dvypwyb bxahfzcfanteibiltins ueebf lqhflvwxksi dc kw ytzzlm gximjuhzfdjuamhsu gdkbmhpnvy i mengfdydekwttkhbzenk wh ldipovluo k nusquzpmnogtjkklfhta nxzgnrveghc mpppfhzjkbucv c uwmahhqradjtf left yzfragcextvx IIJ gzixfeugj rnukjgtjpim haxh ygelddphxnbh rvjxtlqfnlmwdoezh zi bbfj MHS nenrqfkbf spfpazr wc dtd c dtaxhddidfwqs bgnnoxgyynol h dijhrrpnwjlju mukzrrsypzgwvblf zhqi daee r nlipyfszvxlwqwpgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
Assert.AreEqual (output, ReplaceWords (dict, sentence));
}
        [TestMethod]
        Public empty LeetCodeTest ()
{
List dict = new list {"a", "aa", "aaa", "aaaa"
};
chain sentence const = "a aa a aaaa aaa aaa aaaaaaaa bbb baba ababa";
const string output = "a a a a a a a bbb baba a";
Assert.AreEqual (output, ReplaceWords (dict, sentence));
}

public string ReplaceWords (IList dict, string phrase)
{
TrieNode root = new TrieNode ();
foreach (word var in dict)
{
current var = root;
foreach (var letter in word)
{
if (! current.Edges.TryGetValue (letter, out var output))
{
output = current.Edges[letter] = new TrieNode ();
}
current = output;
}

current.IsTerminal = true;
}

rope[] words = prayer.Split (& # 39; & # 39;);
StringBuilder str = new StringBuilder ();

foreach (var word in words)
{
current var = root;
StringBuilder tempWord = new StringBuilder ();
for (index var = 0; index <word.Length; index ++)
{
letter var = word[index];
// if there are no words that begin with those letters
if (! current.Edges.TryGetValue (letter, out var output))
{
if (current.IsTerminal)
{
str.Append (tempWord + "");
break;
}

str.Append (word + "");
break;
}

tempWord.Append (letter);
// the output is terminal for the case that we have "a" as a word
if (current.IsTerminal || output.IsTerminal)
{
str.Append (tempWord + "");
break;
}
if (index == word.Length-1)
{
str.Append (word + "");
}

current = output;
}
}

str.Length--;
returns str.ToString ();
}
}
}