forked from kelvins/algorithms-and-data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
isogram.go
40 lines (32 loc) · 779 Bytes
/
isogram.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"strings"
"unicode"
)
/*
Instructions
Determine if a word or phrase is an isogram.
An isogram (also known as a "non-pattern word") is a word or phrase without a repeating letter,
however spaces and hyphens are allowed to appear multiple times.
Examples of isograms:
>> lumberjacks
>> background
>> downstream
>> six-year-old
The word isograms, however, is not an isogram, because the s repeats.
*/
func main() {
fmt.Println(IsIsogram("isograms"))
fmt.Println(IsIsogram("isogram"))
}
// IsIsogram returns true if the input s is an isogram
func IsIsogram(word string) bool {
word = strings.ToLower(word)
for i, c := range word {
if unicode.IsLetter(c) && strings.ContainsRune(word[i+1:], c) {
return false
}
}
return true
}