leetcode 87. Scramble String 二分法
来源:互联网 发布:java 2017腾讯面试题 编辑:程序博客网 时间:2024/06/06 04:57
leetcode 87. Scramble String
public class Solution {public static void main(String[] args){String s1 = "ab";String s2 = "ba";Solution s = new Solution();System.out.println(s.isScramble(s1, s2));} public boolean isScramble(String s1, String s2) { if(s1.equals(s2)) return true; int[] letter = new int[26]; if(s1.length()!=s2.length()) return false; for(int i=0;i<s1.length();i++){ letter[s1.charAt(i)-'a']++; letter[s2.charAt(i)-'a']--; } for(int i=0;i<26;i++){ if(letter[i]!=0) return false; } for(int i=1;i<s1.length();i++){ if(isScramble(s1.substring(0,i),s2.substring(0,i))&& isScramble(s1.substring(i),s2.substring(i))) return true; if(isScramble(s1.substring(0,i),s2.substring(s2.length()-i)) &&isScramble(s1.substring(i),s2.substring(0,s2.length()-i))) return true; } return false; }}
阅读全文
0 0
- 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 87. 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]87.Scramble String
- [LeetCode] 87. Scramble String
- 【LeetCode】87. Scramble String
- [LeetCode]87. Scramble String
- [leetcode] 87. Scramble String
- Web Server & Web Technology(计算机网络技术)
- 根据国家 ID 和运输方式正则限制字样
- BRVAH官方使用指南
- 在Windows下搭建Gitlab服务器
- 深入理解Java虚拟机(三)性能监控、优化
- leetcode 87. Scramble String 二分法
- 使用Zend Studio或myeclipse做PHP开发的速度优化方法
- AES加密算法(加密文件):Rijndael
- hdu2643
- Linux学习------目录架构
- bzoj1850: Submatrix
- leetcode解题报告22. Generate Parentheses
- POJ 3422 Kaka's Martix Travels 费用流模板
- php 实现信息采集(网页内容抓取)程序代码