MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / partition

Method partition

java/0131-palindrome-partitioning.java:3–18  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

1public class Solution {
2
3 public List<List<String>> partition(String s) {
4 List<List<String>> res = new ArrayList<List<String>>();
5 if (s.equals("")) {
6 res.add(new ArrayList<String>());
7 return res;
8 }
9 for (int i = 0; i < s.length(); i++) {
10 if (isPalindrome(s, i + 1)) {
11 for (List<String> list : partition(s.substring(i + 1))) {
12 list.add(0, s.substring(0, i + 1));
13 res.add(list);
14 }
15 }
16 }
17 return res;
18 }
19
20 public boolean isPalindrome(String s, int n) {
21 for (int i = 0; i < n / 2; i++) {

Callers

nothing calls this directly

Calls 3

isPalindromeMethod · 0.95
equalsMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected