网易内推2017最长01子串
2017-08-12 17:04
211 查看
import java.util.Scanner; /** * Created by Administrator on 2017/8/12. * 如果一个01串任意两个相邻位置的字符都不一样,称为01串 * 输出最长的子串长度 * 解法:最笨的o(n^2); */ public class wangyiFirst { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str; int max = 0; //while (sc.hasNext()) { //} str = sc.next(); max = sovle(str); System.out.print(max); } private static int sovle(String str) { int max = 0; for (int i = 0; i < str.length(); i++) { int sum = 0; int index = 0; char q = str.charAt(i); for (int j = i + 1; j < str.length(); j++) { if (str.charAt(j) == q) { index = j - i; break; }else { q = str.charAt(j); index = j - i + 1; } } max = Math.max(max, index); } return max; } }
相关文章推荐
- 2018校招网易笔试——最长01交错子串
- 最长的含有相同数目的01子串 & 括号匹配问题
- 最长01子串
- 九章算法面试题34 最长01子串
- 网易2017春招笔试 双核处理 01背包
- 九章算法面试题34 最长01子串
- 美团2017校招-最长公共连续子串
- 南华新生训练2017-最长回文子串
- [经典面试题]最长01子串
- [hiho 01]最长回文子串、Manacher算法
- 网易2017校招 [编程题] 最长公共子括号序列@Java
- [编程题] 最长公共连续子串(美团点评2017秋招)
- 网易2017秋招笔试题3:最长公共子括号序列长度
- 最长递增子序列A (完美2017实习生)
- L2-008. 最长对称子串
- 【LeetCode】Longest Substring Without Repeating Characters && 【九度】题目1530:最长不重复子串
- 字符串应用之最长公共子序列和最长公共子串
- POJ 1743 Musical Theme(后缀数组 求最长不重复子串)
- 【51NOD-0】1089 最长回文子串 V2(Manacher算法)
- 网易2017内推-藏宝图