[LeetCode]87 Scramble String
2015-01-06 10:59
330 查看
https://oj.leetcode.com/problems/scramble-string/
http://blog.csdn.net/linhuanmars/article/details/24506703
http://blog.csdn.net/linhuanmars/article/details/24506703
public class Solution { public boolean isScramble(String s1, String s2) { if (s1 == null || s2 == null || s1.length() != s2.length()) return false; if (s1.isEmpty() && s2.isEmpty()) return true; int length = s1.length(); boolean r[][][] = new boolean[length][length][length + 1]; // 1 -> length; for (int i = 0 ; i < length ; i ++) { for (int j = 0 ; j < length ; j ++) { r[i][j][1] = s1.charAt(i) == s2.charAt(j); } } for (int len = 2 ; len <= length ; len ++) { for (int i = 0 ; i < length - len + 1 ; i ++) { for (int j = 0 ; j < length - len + 1 ; j ++) { for (int k = 1 ; k < len ; k ++) { r[i][j][len] |= (r[i][j][k] && r[i + k][j + k][len - k]) || (r[i][j + len - k][k] && r[i + k][j][len - k]); } } } } return r[0][0][length]; } }
相关文章推荐
- LeetCode(87) Scramble String
- leetCode 87. Scramble String
- leetCode 87.Scramble String (拼凑字符串) 解题思路和方法
- leetcode 87 Scramble String(动态规划)
- 【C++】 LeetCode 87. Scramble String
- LeetCode 87 Scramble String
- LeetCode87 Scramble String
- leetCode 87.Scramble String (拼凑字符串) 解题思路和方法
- LeetCode87——Scramble String
- leetcode - 87.Scramble String
- [LeetCode]87. Scramble String
- 【LeetCode】87. Scramble String
- 算法学习之动态规划(leetcode 87. Scramble String)
- Leetcode 87. Scramble String
- [LeetCode] 87. Scramble String 爬行字符串
- [Leetcode]@python 87. Scramble String.py
- [LeetCode] 87. Scramble String
- Leetcode: 87. Scramble String
- 【LeetCode】87. Scramble String
- 87. Scramble String Leetcode Python