We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d783985 commit d0bcc65Copy full SHA for d0bcc65
1 file changed
palindrome/ruby/palindrome.rb
@@ -0,0 +1,27 @@
1
+string = ARGV[0]
2
+
3
+def check_palindrome(str)
4
+ str_unique = find_unique(str)
5
+ values = str_unique.values
6
+ count_of_1_char = values.count 1
7
+ count_of_zero_char = values.count 0
8
+ len = values.length
9
+ if count_of_1_char == 1 || count_of_zero_char == values.length
10
+ puts "String can be a palindrome"
11
+ else
12
+ puts "String can not be a palindrome"
13
+end
14
15
16
17
+def find_unique(str)
18
+ a = {}
19
+ str.each_char do |chars|
20
+ cnt = str.count chars
21
+ a[chars] = cnt%2 unless a.key? chars
22
+ end
23
+ a
24
25
26
+check_palindrome(string)
27
0 commit comments