确定字符互异
来源:互联网 发布:中宏产业数据库 编辑:程序博客网 时间:2024/05/18 13:26
这是题目链接
暴力法
注意:题目要求不能用额外的空间
时间复杂度 = min( 257 , str.length())* min(257, str.length())
import java.util.*;public class Different { public boolean checkDifferent(String iniString) { if(iniString == null){ return true; } int len = iniString.length(); if(len == 0){ return true; } for(int i=0;i<len;i++){ for(int j=i+1;j<len;j++){ if(iniString.charAt(i) == iniString.charAt(j)){ return false; } } } return true; }}
排序的做法
算法:我们先排序,然后再扫一遍排序后的字符串,查看是否有重复字符。时间复杂度O(nlogn) + n
package 确定字符互异;import java.util.*;public class Different { public boolean checkDifferent(String iniString) { if(iniString == null){ return true; } int len = iniString.length(); if(len == 0){ return true; } char[] str = iniString.toCharArray(); Arrays.sort(str); for(int i=0;i<len-1;i++){ if(str[i] == str[i+1]) { return false; } } return true; } public static void main(String[] args){ System.out.println(new Different().checkDifferent("acbdesy")); }}
0 0
- 确定字符互异
- 确定字符互异
- 确定字符互异
- 确定字符互异
- 确定字符互异
- 确定字符互异
- 确定字符互异
- 确定字符互异
- 确定字符互异
- 确定字符互异
- 确定字符互异
- 确定字符互异
- 确定字符互异
- 确定两串乱序同构 、原串翻转、确定字符互异
- 确定字符互异(Java)
- 第二天 确定字符互异
- 确定字符互异想法整理
- 确定字符互异Java实现
- 关于3D-HEVC中的SDC编码方式
- Spring mvc4 + ActiveMQ 整合
- Spark MLlib聚类clustering:KMeans K均值 ---原理及实战
- 伯乐在线
- 信息隐藏课程之索引图像的隐写
- 确定字符互异
- PAT_乙级 1011 A+B和C
- LeetCode-Balanced Binary Tree
- Spring基础:快速入门spring(4):setter注入
- 模式识别五--PCA主分量分析与Fisher线性判别
- C语言题目
- 模式识别六--感知器的实现
- git svn
- 模拟退火算法求函数最小值问题的C/C++实现