-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution_30.java
More file actions
35 lines (31 loc) · 921 Bytes
/
Solution_30.java
File metadata and controls
35 lines (31 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.hilbert25.leetcode;
import java.util.ArrayList;
import java.util.List;
/**
* @author : hilbert25
* @version 创建时间:2017年4月11日 上午12:34:21 LeetCode com.hilbert25.leetcode
* Solution_30
*/
public class Solution_30 {
public static void main(String[] args) {
// TODO Auto-generated method stub
findSubstring("abarfoothefoobarman", new String[] { "foo", "bar", "man" });
}
public static List<Integer> findSubstring(String s, String[] words) {
List<Integer> list = new ArrayList<>();
int begin = s.length() - 1;
int end = s.length() - 1;
for (int i = 0; i < words.length; i++) {
int a = s.indexOf(words[i]);
begin = begin > a ? a : begin;
int b = s.indexOf(words[i], a + 1);
if (b != -1)
end = end > b ? b : end;
else
end = end > a + words[0].length() ? end : a + words[0].length();
}
list.add(begin);
list.add(end);
return list;
}
}