-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdetermine_if_string_halves_are_alike.go
83 lines (72 loc) · 1.66 KB
/
determine_if_string_halves_are_alike.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
// func halvesAreAlike(s string) bool {
// var st string = strings.ToLower(s)
// var char []string = strings.Split(st, "")
// var count int = 0
// for i := 0; i < len(char); i++ {
// if i == 'a' || i == 'e' || i == 'i' || i == 'o' || i == 'u' {
// count++
// }
// }
// if count%2 == 0 {
// return true
// }
// return false
// }
//=========== 2
// func halvesAreAlike(s string) bool {
// var firstCount int = 0
// var secondCount int = 0
// for i := 0; i < len(s)/2; i++ {
// if s[i] == 'a' ||
// s[i] == 'e' ||
// s[i] == 'i' ||
// s[i] == 'o' ||
// s[i] == 'u' ||
// s[i] == 'A' ||
// s[i] == 'E' ||
// s[i] == 'I' ||
// s[i] == 'O' ||
// s[i] == 'U' {
// firstCount++
// }
// }
// for i := len(s) / 2; i < len(s); i++ {
// if s[i] == 'a' ||
// s[i] == 'e' ||
// s[i] == 'i' ||
// s[i] == 'o' ||
// s[i] == 'u' ||
// s[i] == 'A' ||
// s[i] == 'E' ||
// s[i] == 'I' ||
// s[i] == 'O' ||
// s[i] == 'U' {
// secondCount++
// }
// }
// if firstCount == secondCount {
// return true
// }
// return false
// }
//============= 3
/*
bool halvesAreAlike(String s) {
// set of Vowels
HashSet<String> vowels =
HashSet.of(['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']);
// just to count each and every value of occurrence
int count = 0;
//loop for each element in the string
for (int i = 0; i < s.length; i++) {
// if they both match
if (vowels.contains(s[i])) {
// we will set the value to count
count += (s.length - 2 * i - 1).sign;
}
}
// than return based on the matching
return count == 0;
}
*/