substring

Find all possible substring in fastest way [duplicate]

五迷三道 提交于 2020-05-25 03:36:31
问题 This question already has answers here : Generate all unique substrings for given string (14 answers) Closed 2 years ago . For String A = "abcd" then answer should be {a,ab,abc,abcd,b,bc,bcd,c,cd,d} To find all the substring I have used following method for (int i = 0; i < A.length(); i++) { for (int j = i+1; j <= A.length(); j++) { System.out.println(A.substring(i,j)); } } But according to my understanding the complexity goes to O(N^2) . Can we make it faster? I referred previous question

Difference between substring in Postgresql

久未见 提交于 2020-05-24 03:31:07
问题 I was checking the PostgreSQL Manual the last days and I have noticed that substring() is explained there with substring('string' FROM [int] FOR [int]) . I normally just use substring('string', [int], [int]) because I learned it that way from MySQL my simple question is now if this two have any differences is the first one maybe the better choice to use in PostgreSQL or does do the same and these are just 2 different kinds of doing the same thing? 回答1: SUBSTRING(char_exp FROM start_position

Get all characters after the last '/' (slash) from url string

為{幸葍}努か 提交于 2020-04-29 11:58:21
问题 How to get all characters after the last '/' (slash) from url string? I receive a json string from my URL scheme when making webview request for certain site. For example: app://ga/ecommerce/%7B%22product%22:%22playstation4%22...}] I would like to grab the substring after the last '/'(slash). How can I achieve it? May I know what is the format of Regex? Avoid to use NSRange lastDotRange = [sURL rangeOfString:@"/" options:NSBackwardsSearch]; because I might have escaped '/' in my json. Thank

Substring to Get Text after Second Period in Powershell

谁都会走 提交于 2020-04-11 04:38:11
问题 I am working with a Substring that will give me everything before the 2nd '.' I've worked with substrings before to get everything before the 1st '.' $id = $file.Substring(0, $File.LastIndexof('.')) and it works perfectly. For this second substring this is what I have thus far $netVerShort = $netVer.Substring(0, 2nd ('.')) but I'm certain this isn't right. The value I get from $netVer is 2.0.5727 and with this second substring I'm trying to get it to return 2.0 回答1: Not necessarily the most

hive中的内置函数parse_url_tuple() 和内置函数 lateral view和 parse_url

大憨熊 提交于 2020-04-07 17:08:09
hive中的内置函数parse_url_tuple() 和内置函数 lateral view 1.parse_url () 解析URL字符串,partToExtract的选项包含[HOST,PATH,QUERY,REF,PROTOCOL,FILE,AUTHORITY,USERINFO]。 【host,path,query,ref,protocol,file,authority,userinfo】这些可以理解为关键字 通过关键字可以获得url中对应的字段数据。 parse_url_tuple功能类似parse_url(),但它可以同时提取多个部分并返回 举例 : select parse_url(‘http://facebook.com/path/p1.php?query=1’, ‘PROTOCOL’) from dual; --http select parse_url(‘http://facebook.com/path/p1.php?query=1’, ‘HOST’) from dual;—facebook.com​ select parse_url(‘http://facebook.com/path/p1.php?query=1’, ‘REF’) from dual;—空​ select parse_url(‘http://facebook.com/path/p1.php

003 Longest Substring Without Repeating Characters

孤街醉人 提交于 2020-04-07 02:24:37
看到这题,本来想用字符串做来着,不过一时之间忘了字符串中的indexOf函数了,倒是想起了字符串转数组的函数split(尴尬),于是就转为数组了。 后来看了题解后换成字符串检索,果然快了10ms左右。 思路其实挺简单,就是遍历一次字符串,然后检测这个字符在之前出现过没有,没有的话就加在后边, 有的话就先计算之前的字符串长度与max比较,然后删除出现的字符及之前的字符串, 接着把新来的字符放入temp后边。最后在比较一次字符串长度就结束。 /** * @param {string} s * @return {number} */ var lengthOfLongestSubstring = function(s) { // let temp = [] // let max=0 // s.split('').map((d)=>{ // let index=temp.indexOf(d) // if(index!=-1) // { // temp.length>max && (max=temp.length) // temp.splice(0,index+1) // } // temp.push(d) // }) // temp.length>max &&(max=temp.length) // return max let temp='' let max=0 for(n of s) {

JavaScript 浏览器类型及版本号

前提是你 提交于 2020-03-29 08:04:43
项目中偶尔用到判断浏览器类型及相关版本问题,现记录相关代码: function getBrowserVertion(userAgent) { var browserName, browserVersion, types, Info; if (userAgent.indexOf("MSIE") > -1) { types = userAgent.substring(userAgent.indexOf("MSIE")); Info = (types.split(";")[0]).split(" "); browserName = Info[0]; browserVersion = Info[1]; } else if (userAgent.indexOf("Firefox") > -1) { types = userAgent.substring(userAgent.indexOf("Firefox")); Info = (types.split(" ")[0]).split("/"); browserName = Info[0]; browserVersion = Info[1]; } else if (userAgent.indexOf("Chrome") > -1) { types = userAgent.substring(userAgent.indexOf("Chrome")

JavaScript进阶(三)之对象

陌路散爱 提交于 2020-03-28 04:28:49
返回星期方法 getDay() 返回星期,返回的是0-6的数字,0 表示星期天。如果要返回相对应“星期”,通过数组完成,代码如下: <script type="text/javascript"> var mydate=new Date();//定义日期对象 var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]; //定义数组对象,给每个数组项赋值 var mynum=mydate.getDay();//返回值存储在变量mynum中 document.write(mydate.getDay());//输出getDay()获取值 document.write("今天是:"+ weekday[mynum]);//输出星期几 </script> 注意:以上代码是在2014年3月7日,星期五运行。 结果: 5 今天是:星期五 <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>获得星期</title> <script type="text/javascript"> var mydate=new Date(); var weekday=["星期日","星期一","星期二",

161. One Edit Distance

[亡魂溺海] 提交于 2020-03-27 02:21:36
题目: Given two strings S and T, determine if they are both one edit distance apart. 链接: http://leetcode.com/problems/one-edit-distance/ 6/14/2017 2ms, 58% 提交好几次才通过,所以代码像打补丁一样。注意的test case: 2个空string -- false 相同的string -- false 当检查出来不一致时,根据长度来比较之后的substring 1 public class Solution { 2 public boolean isOneEditDistance(String s, String t) { 3 if (s == null || t == null) { 4 return false; 5 } 6 int sLen = s.length(); 7 int tLen = t.length(); 8 if (sLen == 0 && tLen == 0) { 9 return false; 10 } 11 if (sLen == 0 && tLen == 1 || sLen == 1 && tLen == 0) { 12 return true; 13 } 14 if (Math.abs(sLen -

3. Longest Substring Without Repeating Characters

我的梦境 提交于 2020-03-26 01:06:24
题目描述 题目思路: 这道题要求的是最长的子串而不是最长的子序列,在LeetCode上也给了提示 Note that the answer must be a substring, "pwke" is a subsequence and not a substring. 先不考虑代码的问题,比如有一个字符串“abcabcbb”,要求找出其最长子串,可以一个一个字符的遍历,a,b,c,然后又出现了a,就把一开始已经遍历到的a去掉,变成b,c,a。然后遍历到b,就把已经遍历过的b去掉,变成c,a,b。重复这个过程,最终可以找到最长子串。 从上面的过程中可以看到,我们需要记录之前已经出现过的字符,可以统计字符出现的个数,但是这道题目,字符出现的顺序很重要,所以可以使用Hashmap来建立字符和位置之间的映射(一开始我也没有想到用Hashmap,是从网上查找资料才明白的)。之前我们手动找子串的过程实际是一个滑动窗口的过程,窗口内都是没有重复出现的字符,由于窗口在不断的向右滑动,因此只需要关心每一个字符最后出现的位置即可,并把这个位置和字符建立映射。 为了确定窗口的大小,就必须有一个left指针来指向窗口的前一个位置。然后i向右滑动,i - left就是当前窗口的大小(也是当前能找到的最长子串的长度)。 当窗口向右滑动,i++。遇到新的元素s[i],先判断该元素在Hashmap中有没有