c# LCP
public static string LCP(string[] words)
{
string result = "";
if (words.Length == 0 || words == null) return "None in common";
// shortest to longest by word count ... optional
var orderedWords = words.OrderBy(x => x.Length)
.ToArray();
for (int i = 0; i < words.Length - 1; i++)
{
//hold each word to compare against 1st word
string fixedWord = words[0].Substring(0, i + 1);
for (int j = 1; j < words.Length; j++)
{
//compare 1st word by letter against each other word
string currentWord = words[j].Substring(0, i + 1);
if (fixedWord == currentWord)
{
// just the char's that match
result = currentWord;
}
else if (fixedWord != currentWord)
{
return result.Substring(0, currentWord.Length - 1);
}
}
}
return result;
}
Also in C#:
- rotate object towards target rotation slowly unity
- dynamic group by expression C#
- how to start an if statement in c#
- c# access session in class
- gfortran: declare an array
- quaternion euler
- or in unity
- unity set material color
- can't add an editor script
- display none asp.net
- c# LCP
- c# delegate return value invoke
- how to mock abstract httpcontext using moq .net core
- how to make a game
- open zip file in c#
- c# remove spaces from string
- unity set list of strings
- c# find comma in text and remove
- Exception thrown: 'System.FormatException' in mscorlib.dll dates
- c# datetime dd/mm/yyy hh:mm:ss
- convert array object to int[] c#
- c# sql duplicate key exception
- nunit return parameter