從傳入參數 haystack
中找出參數 needle
中的索引位置,非常基礎的一題
我的答案
1 2 3 4 5 6 7 8 9 10 11 |
public class Solution { public int StrStr(string haystack, string needle) { if(needle == null || needle == string.Empty){ return 0; } else if(haystack == null){ return -1; } return haystack.IndexOf(needle); } } |