We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 3ea0fd8 + cf41657 commit 2416657Copy full SHA for 2416657
ruby/0131-palindrome-partitioning.rb
@@ -0,0 +1,33 @@
1
+def partition(s)
2
+ @result = []
3
+ @part = []
4
+ @s = s
5
+
6
+ def dfs(i)
7
+ if i >= @s.length
8
+ @result.append(@part.dup())
9
+ return
10
+ end
11
+ (i..@s.length-1).each do |j|
12
+ if is_palindrome(@s,i,j)
13
+ @part.append(@s[i..j])
14
+ dfs(j+1)
15
+ @part.pop()
16
17
18
19
20
+ dfs(0)
21
22
+ return @result
23
+end
24
25
26
+def is_palindrome(s,i,j)
27
+ while i<j
28
+ return false if s[i] != s[j]
29
+ i +=1
30
+ j -=1
31
32
+ return true
33
0 commit comments