admin管理员组

文章数量:1636999

Implement strStr().

Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.

注意 "","" 的情况

Source

<pre name="code" class="java">public class Solution{
	public String strStr(String haystack, String needle) {
		int i = haystack.indexOf(needle);		//indexOf返回子串的位置
		if(i == -1) return null;		//返回-1为未找到
		else return haystack.substring(i);		//函数要求返回值为string,所以不能只返回子串位置
    }
	
}


 

本文标签: implementstrStrJava