-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsolution.rb
More file actions
52 lines (39 loc) · 848 Bytes
/
Copy pathsolution.rb
File metadata and controls
52 lines (39 loc) · 848 Bytes
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
module Solution1
def self.get_duplicated_arguments(*strings)
strings
.group_by(&:itself)
.transform_values(&:length)
.select { |k, v| v > 1 }
.keys
end
end
module Solution2
def self.get_duplicated_arguments(*strings)
pointer1 = 0
pointer2 = 1
result = Set.new
sorted = strings.sort
(0...sorted.length).each do
if sorted[pointer1] == sorted[pointer2]
result << sorted[pointer1]
end
pointer1 += 1
pointer2 += 1
end
result.to_a
end
end
module Solution3
def self.get_duplicated_arguments(*strings)
result = Set.new
(0...strings.length).each do |i|
((i + 1)..(strings.length)).each do |j|
if strings[i] == strings[j]
result << strings[i]
break
end
end
end
result.to_a
end
end