LeetCode算法题3:Longest Substring Without Repeating Characters
2015-07-28 16:36
405 查看
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “bbbbb” the longest substring is “b”, with the length of 1.
public class LongestSubstring { public static void main(String[] args) { // TODO Auto-generated method stub LongestSubstring lsrc = new LongestSubstring(); String s= "abcabcbb"; lsrc.lengthOfLongestSubstring(s); } public int lengthOfLongestSubstring(String s) { int i=0,j=1; StringBuffer sb = new StringBuffer(); if(s.length()==0) return 0; if(s.length()==1) return 1; int Lf = 0; int Le = 1; for (Le = 1; Le < s.length(); Le++) { while (s.charAt(Lf + i) != s.charAt(Le)) { i++; } if (i == (Le - Lf)) { if ((i + 1) > j) { j = i + 1; } i = 0; continue; } else { sb.append(i + 1); Lf = Lf + i + 1; i = 0; } } System.out.println("j=" + j); return sb.length(); } }
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树
- [原创]java局域网聊天系统