Skip to content

Commit d0bcc65

Browse files
OarpitOt2013anurag
authored andcommitted
1 parent d783985 commit d0bcc65

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

palindrome/ruby/palindrome.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
end
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+
end
25+
26+
check_palindrome(string)
27+

0 commit comments

Comments
 (0)