Skip to content

Commit 4fac746

Browse files
authored
Merge pull request #1850 from saip7795/sp/partition-labels
Create: 0763-Partition-Labels.rb
2 parents 684dcec + d52f2b4 commit 4fac746

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

ruby/0763-partition-labels.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
def partition_labels(s)
3+
last_index = Hash.new(0)
4+
5+
s.each_char.with_index do |char,index|
6+
last_index[char] = index
7+
end
8+
9+
result = []
10+
size = s_end = 0
11+
12+
s.each_char.with_index do |char,index|
13+
size +=1
14+
s_end = [last_index[char],s_end].max
15+
16+
if (index == s_end)
17+
result.append(size)
18+
size =0
19+
end
20+
end
21+
22+
return result
23+
24+
end

0 commit comments

Comments
 (0)