Last active
September 24, 2018 17:59
-
-
Save ClintChil/e1afdb0443e87a065d3926eaefc9f805 to your computer and use it in GitHub Desktop.
String Manipulaiton Practice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
// To execute C#, please define "static void Main" on a class | |
// named Solution. | |
class Solution { | |
static string ReverseString(string inputString) { | |
if (inputString.Length <= 1) | |
return inputString; | |
else | |
return ReverseString(inputString.Substring(1, inputString.Length - 1)) + inputString[0]; | |
} | |
static void Main(string[] args) { | |
var firstName = "Tom"; | |
var lastName = "Smith"; | |
var fullName = firstName + " " + lastName; | |
Console.WriteLine(ReverseString(firstName)); | |
Console.WriteLine(ReverseString("Google")); | |
} | |
} | |
using System; | |
class Solution { | |
static string Sort(string s) { | |
char[] content = s.ToCharArray(); | |
Array.Sort(content); | |
return new string(content); | |
} | |
static bool Permutation(string s, string t) { | |
if (s.Length != t.Length) { | |
return false; | |
} else { | |
return Sort(s).Equals(Sort(t)); | |
} | |
} | |
static void Main(string[] args) { | |
Console.WriteLine(Permutation("taco", "cato")); | |
Console.WriteLine(Permutation("taco", "catt")); | |
} | |
} | |
using System; | |
class Solution { | |
static string Reverse(string str) { | |
string stringBuffer = String.Empty; | |
int length = str.Length; | |
for (int i = length - 1; i >= 0; i--) { | |
stringBuffer += str[i]; | |
} | |
return stringBuffer; | |
} | |
static void Main(string[] args) { | |
Console.WriteLine(Reverse("taco")); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment