substring

map + 前缀和

怎甘沉沦 提交于 2020-02-18 07:34:42
B. Balanced Substring time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a string s consisting only of characters 0 and 1. A substring [ l ,  r ] of s is a string s l s l  + 1 s l  + 2 ... s r , and its length equals to r  -  l  + 1. A substring is called balanced if the number of zeroes ( 0) equals to the number of ones in this substring. You have to determine the length of the longest balanced substring of s . Input The first line contains n ( 1 ≤  n  ≤ 100000) — the number of characters in s . The second line contains a

${fn: }函数

旧时模样 提交于 2020-02-16 18:34:36
函数名 函数说明 使用举例 fn:contains 判断字符串是否包含另外一个字符串 <c:if test="${fn:contains(name, searchString)}"> fn:containsIgnoreCase 判断字符串是否包含另外一个字符串(大小写无关) <c:if test="${fn:containsIgnoreCase(name, searchString)}"> fn:endsWith 判断字符串是否以另外字符串结束 <c:if test="${fn:endsWith(filename, ".txt")}"> fn:escapeXml 把一些字符转成XML表示,例如 <字符应该转为< ${fn:escapeXml(param:info)} fn:indexOf 子字符串在母字符串中出现的位置 ${fn:indexOf(name, "-")} fn:join 将数组中的数据联合成一个新字符串,并使用指定字符格开 ${fn:join(array, ";")} fn:length 获取字符串的长度 , 或者数组的大小 ${fn:length(shoppingCart.products)} fn:replace 替换 字符串中指定的字符 ${fn:replace(text, "-", "&#149;")} fn:split 把字符串按照指定字符切分 ${fn

bash, extract string before a colon

*爱你&永不变心* 提交于 2020-02-12 06:50:47
问题 If I have a file with rows like this /some/random/file.csv:some string /some/random/file2.csv:some string2 Is there some way to get a file that only has the first part before the colon, e.g. /some/random/file.csv /some/random/file2.csv I would prefer to just use a bash one liner, but perl or python is also ok. 回答1: cut -d: -f1 or awk -F: '{print $1}' or sed 's/:.*//' 回答2: Another pure BASH way: > s='/some/random/file.csv:some string' > echo "${s%%:*}" /some/random/file.csv 回答3: Try this in

bash, extract string before a colon

非 Y 不嫁゛ 提交于 2020-02-12 06:46:06
问题 If I have a file with rows like this /some/random/file.csv:some string /some/random/file2.csv:some string2 Is there some way to get a file that only has the first part before the colon, e.g. /some/random/file.csv /some/random/file2.csv I would prefer to just use a bash one liner, but perl or python is also ok. 回答1: cut -d: -f1 or awk -F: '{print $1}' or sed 's/:.*//' 回答2: Another pure BASH way: > s='/some/random/file.csv:some string' > echo "${s%%:*}" /some/random/file.csv 回答3: Try this in

03.Longest Substring Without Repeating Characters

十年热恋 提交于 2020-02-12 05:44:34
Longest Substring Without Repeating Characters(最长的子串不重复字符) 题目要求: 给定一个字符串,找到最长的子字符串的长度,要求不重复字符。 例如:    给定一个字符串“abcabcbb”,答案是“abc”,长度是3。   给定一个字符串“bbbbb”,答案是“b”,长度是1。   给定一个字符串“pwwkew”,答案是“wke”,长度是3。    注意:答案必须是一个子字符串,“pwke”是一个子序列,而不是一个子字符串。 解法一:   思路:基本思想为建立一个散列表来存储字符串中的字符。以字符为键,字符所处位置为值。设置两个值start,end来扫描字符串,同时更新散列表。如果该字符已经存在于散列表中,则更新start值,将start值赋值为最后找到的同一个字符的右侧。 1 public class LongestSubstringWithoutRepeatingCharacters { 2 3 public static void main(String[] args) { 4 Scanner scanner = new Scanner(System.in); 5 String string = scanner.nextLine(); 6 System.out.println("最长不重复子串的长度为:" +

Longest Substring Without Repeating Characters

♀尐吖头ヾ 提交于 2020-02-12 05:35:49
LeetCode OJ 3: Given a string, find the length of the longest substring without repeating characters. Given "abcabcbb" , the answer is "abc" , which the length is 3. Given "bbbbb" , the answer is "b" , with the length of 1. Given "pwwkew" , the answer is "wke" , with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring. 思路1:本题的任务是得到没有重复字符的最长子串的长度。我的解法是使用i和j两个指针进行搜索,i代表候选的最长子串的开头,j代表候选的最长子串的结尾。搜索过程中,如果字符j重复出现,则从重复字符第一次出现的位置开始重新搜索,直到遍历所有的可能性。 时间复杂度:O(N²) int lengthOfLongestSubstring(string s) {   int maxLen, i, j, k, curLen;   int char_int_arr

LeetCode---------Longest Substring Without Repeating Characters解法

删除回忆录丶 提交于 2020-02-12 04:59:22
题目如下: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb" , the answer is "abc" , which the length is 3. Given "bbbbb" , the answer is "b" , with the length of 1. Given "pwwkew" , the answer is "wke" , with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring. 大致翻译: 给出一个字符串,求出没有重复字符的最长子串的长度。 例如: 给出"abcabcbb",答案是"abc"的长度为3. 给出"bbbbb",答案是"b"的长度为1. 给出"pwwkew",答案是"wke"的长度为3. 注意答案必须是一个子串,"pwke"是一个子序列但并不是子串. 本题重点在于不重复的子串,想到HashSet是不允许存储重复的数据的,所以解法就利用HashSet来实现。 【Java代码】 public class

Longest Substring Without Repeating Characters

你。 提交于 2020-02-12 04:23:45
leetCode题目: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb" , the answer is "abc" , which the length is 3. Given "bbbbb" , the answer is "b" , with the length of 1. Given "pwwkew" , the answer is "wke" , with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring. 需要注意边缘测试用例如"C",以及超长测试用例,还需要注意子串和子序列的区别 解法1:遍历字符串的每个字符,计算出以该字符为开始的最长子串,假设该字符串长度为N,则算法时间复杂度最大为N的平方 golang Code:func lengthOfLongestSubstring(s string) int { var buf bytes.Buffer maxLength := 0 currentLength := 0 for index :

Longest Substring Without Repeating Characters

北战南征 提交于 2020-02-12 01:18:34
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. 思路:本题找出字符串中最长的 不包含相同的字符 的子字符串不包含相同的字符。可以使用hash表来解决这道题。主要思路就是使用两个头尾指针,尾指针不断往后搜索,当该字符在前面出现过了,记录字符的长度和最长结果,此时头指针不断往后搜索,同时记录的长度count要减一,直到头指针指向的字符与尾指针相同时结束搜索,同时头指针向后移动一位,记录访问过的字符,长度count加一。最后优化最长结果。 class Solution { public: int lengthOfLongestSubstring(string s) { int n=s.size(); if(n<=1) return n; int result=0; int count=0; int begin=0;

货币数值小写转换大写

南楼画角 提交于 2020-02-12 01:16:52
检测模块: 1 import org.junit.Test; 2 3 public class IoDetection 4 { 5 private static int a = 0;// 如果为零表示val为数值 6 7 @Test 8 public void ioDetection(String var) 9 { 10 String[] str = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", 11 "9", ".", "0" }; 12 if (null == var) 13 { 14 System.out.println("不可输入空值!"); 15 System.exit(0); 16 } 17 try 18 { 19 String intVar = var.substring(0, 1); 20 // 提取用户录入正数位 21 for (int j = 1; j < var.length(); j++) 22 { 23 if (".".equals(var.substring(j - 1, 24 var.length() - (var.length() - j)))) 25 { 26 break; 27 } 28 else 29 { 30 intVar += var.substring(j, j + 1);