diff --git a/algorithms/Go/strings/anagram.go b/algorithms/Go/strings/anagram.go index 6ae30240..ca290e8d 100644 --- a/algorithms/Go/strings/anagram.go +++ b/algorithms/Go/strings/anagram.go @@ -1,29 +1,23 @@ -package main - /** Problem Statement: Given two strings s and t, find they are anagrams or not An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. -**/ - -/*** Example 1: Input: s="anagram" t="nagaram" Output: true Example 2: Input: s="rat" t="car" Output: false -***/ - -/*** Time complexity: O(n), n=length of string s Space complexity: O(1) **/ +package strings + import "fmt" -func main() { +func RunIsAnagram() { fmt.Println("Enter first string") var first string fmt.Scanln(&first) @@ -37,9 +31,10 @@ func main() { fmt.Println("They are not anagrams") } } + func isAnagram(s string, t string) bool { var count [256]int - //var i int + for i := 0; i < len(s); i++ { count[s[i]]++ } diff --git a/algorithms/Go/strings/palindrome-permutation.go b/algorithms/Go/strings/palindrome-permutation.go index 779f8660..62b158a9 100644 --- a/algorithms/Go/strings/palindrome-permutation.go +++ b/algorithms/Go/strings/palindrome-permutation.go @@ -1,3 +1,10 @@ +/* +Given a string s, return true if we can have a palindrome from the permutation of the input +A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar. + + Time: O(n) + Space: O(n) +*/ package strings import( @@ -5,12 +12,7 @@ import( "fmt" ) -/* -Given a string s, return true if we can have a palindrome from the permutation of the input - Time: O(n) - Space: O(n) -*/ func canPermutePalindrome(s string) bool { a := strings.Split(s,"") dictionary := make(map[string] int) @@ -29,7 +31,7 @@ func canPermutePalindrome(s string) bool { //You are welcome to play around with the test cases -func runPermutationCheck(){ +func RunPermutationCheck(){ input1 := "carerac" fmt.Printf("%t for input %s \n", canPermutePalindrome(input1), input1) //should print true