從入門到放棄

興趣使然的軟體工程師,擅長 Exception。

  • GitHub
  • About

[C#][LeetCode] 28. Implement strStr()

  • 作者lex.xu
  • /
  • 6 月 03, 2018
  • /
  • 心得筆記

從傳入參數 haystack 中找出參數 needle 中的索引位置,非常基礎的一題

我的答案

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);
    }
}

 

相關


標籤: C#, LeetCode

這裡的資訊對您有用嗎?歡迎斗內給我

lex.xu

https://blog.exfast.me/
對資訊技術這方面非常有興趣,常常自學新技術來補齊自己的好奇心,解決問題的成就感是我繼續走向這條路的最大動力。
上一篇文章
下一篇文章

熱門文章

  • [C#] Registrykey 登錄機碼的新增、修改、刪除、讀取
    [C#] Registrykey 登錄機碼的新增、修改、刪除、讀取
  • [C#][ASP.NET MVC5] FileUpload 上傳檔案大小的限制
    [C#][ASP.NET MVC5] FileUpload 上傳檔案大小的限制
  • [MSSQL] 當自動識別欄位需要Insert資料時應該怎麼辦 ?
    [MSSQL] 當自動識別欄位需要Insert資料時應該怎麼辦 ?
  • [Windows Batch] 自動詢問是否以系統管理員身分執行
    [Windows Batch] 自動詢問是否以系統管理員身分執行

近期文章

  • [Linux] 如何新增使用者並給予管理員權限
  • [ASP.Net Core] 如何讓 Godaddy 跑 .NET Core 3.1 ?
  • [Linux] 如何在 Ubuntu 20.04 中使用遠端桌面 ?
  • [MySQL] 資料表結構遷移的好幫手 pt-online-schema-change
  • [Docker] 取得 Container 的 IPAddress

標籤

.NET .NET Core Apache ASP.NET ASP.NET Core ASP.NET MVC ASP.NET WebAPI Bug C# CentOS ChatBot Docker Easy Git IIS IP JavaScript LeetCode Line LinQ Linux Medium MSSQL MySQL NetCore php phpMyAdmin Python Server SQL SQL Server SSL Ubuntu Visual Studio WebAPI Win10 Windows Windows 10 Windows Server WordPress 寶寶 教學 筆記 轉載 遞迴

分類

  • 心得筆記 (197)

適用電子郵件訂閱網站

輸入你的電子郵件地址訂閱網站的新文章,使用電子郵件接收新通知。