标签:io ar java strong on art bs as leetcode
Implement strStr().
Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.
输入两个字符串,如果第二个是第一个的字串返回该串在第一个字符串开始的的子串。
比如abcd bc
则返回bcd
如果没有找到返回null
思路:
用Java轻松水过,用indexOf方法可得到是否有子串与子串的起始标记,
用substring得到从index开始的子串
public class Solution { public String strStr(String haystack, String needle) { int index; index = haystack.indexOf(needle); if(index==-1) return null; else return haystack.substring(index); } }
标签:io ar java strong on art bs as leetcode
原文地址:http://blog.csdn.net/zhuangjingyang/article/details/40482291