leetcode_Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any intervening characters. For example, given:
S: "barfoothefoobarman"
L: ["foo", "bar"] You should return the indices: [0,9].
class Solution {
public:
vector<int> findSubstring(string S, vector<string> &L) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
map<string, int> words;
map<string, int> count;
vector<int> res;
if(L.size() == || S.length() < L[].size()*L.size() ) return res;
for(int i = ; i< L.size(); ++i){
++words[L[i]];
} for(int i= ; i <= S.length()- L[].size()*L.size(); ++i)
{
count.clear();
int j;
for(j = ; j <L.size();++j){
string str = S.substr(i+j*L[].size(), L[].size());
if(words.find(str) == words.end()) break;
count[str]++;
if(count[str] > words[str]) break;
}
if(j == L.size())
res.push_back(i);
}
return res;
}
};
leetcode_Substring with Concatenation of All Words的更多相关文章
- [LeetCode] Substring with Concatenation of All Words 串联所有单词的子串
You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...
- Leetcode Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...
- Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...
- 【leetcode】Substring with Concatenation of All Words
Substring with Concatenation of All Words You are given a string, S, and a list of words, L, that ar ...
- 【leetcode】Substring with Concatenation of All Words (hard) ★
You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...
- LeetCode:Substring with Concatenation of All Words (summarize)
题目链接 You are given a string, S, and a list of words, L, that are all of the same length. Find all st ...
- LeetCode - 30. Substring with Concatenation of All Words
30. Substring with Concatenation of All Words Problem's Link --------------------------------------- ...
- Effective Java 51 Beware the performance of string concatenation
Using the string concatenation operator repeatedly to concatenate n strings requires time quadratic ...
- Java for LeetCode 030 Substring with Concatenation of All Words【HARD】
You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...
随机推荐
- SPOJ 0962 Intergalactic Map
题目大意:在一个无向图中,一个人要从A点赶往B点,之后再赶往C点,且要求中途不能多次经过同一个点.问是否存在这样的路线.(3 <= N <= 30011, 1 <= M <= ...
- cf202-div 1-B - Apple Tree:搜索,数论,树的遍历
http://codeforces.com/contest/348/problem/B B. Apple Tree time limit per test 2 seconds memory l ...
- <WinForm_1>初识WinForm编程
暑假花了一个多月自学了Win32 SDK编程,不敢说成为了高手,但是还是颇具收获——windows的消息机制(著名的消息循环).一切控件均是窗口…… 曾经有一位网友(和我一个专业的)向我吐槽:Win3 ...
- java中的浮点(float)运算
一. 关于浮点运算,需要说明的几点: 1. 在java中,进行浮点运算并不会处理例外情况,所以,即使除数为0,也不会有例外被抛出; 2. 当运算结果是溢出(Infinity)时,结果为Infin ...
- javaweb笔记2之HTTP协议
1 什么是http协议 是浏览器客户端 和 服务器端 数据传输的 格式规范: 2 查看http协议 (1)用火狐的firebug插件查看 (2)使用谷歌的Ghome查看(审查元素-> ...
- [Qt] QString 和 char* 转换
(1) QString 转 char* char acResult[10240]; //QByteArray baResult = strResult.toLatin1(); QByteArray b ...
- 转:Java生成图片验证码(有点仿QQ验证码的意思)
http://blog.csdn.net/ruixue0117/article/details/22829557 java: VerifyCodeUtils.java package com.fro. ...
- android中定位光标位置
edittext.setSelection(int); edittext.setText(123);//设置edittext中的内容 edittext.setSelection(123.length( ...
- C++中数组初始化
#include<iostream>using std::cout;using std::endl;int arr1[5];int arr2[5] = {1,3,5};int main() ...
- sql中的case when
sql语言中有没有类似C语言中的switch case的语句?? 没有,用case when 来代替就行了. 例如,下面的语句显示中文年月 select ...