Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (みけねこ的鼻屎)時間2年前 (2023/09/22 17:17), 編輯推噓0(004)
留言4則, 3人參與, 2年前最新討論串416/719 (看更多)
https://leetcode.com/problems/is-subsequence/description 392. Is Subsequence 給你一個字串 s 和一個字串 t,求出字串 s 是否是 t 的子序列。 思路: 1.左邊指標指向s,右邊指標不斷往右並和s比較,如果左邊指標走到底就返回 true。 Java Code: -------------------------------------- class Solution { public boolean isSubsequence(String s, String t) { if (s.length() == 0) { return true; } int index = 0; for (int i = 0; i < t.length(); i++) { if (s.charAt(index) == t.charAt(i)) { index++; } if (index == s.length()) { return true; } } return false; } } -------------------------------------- -- https://i.imgur.com/YPBHGGE.jpg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.100.73.13 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1695374229.A.4CC.html

09/22 17:23, 2年前 , 1F
return s in t
09/22 17:23, 1F

09/22 17:23, 2年前 , 2F
equal
09/22 17:23, 2F

09/22 17:25, 2年前 , 3F
Python,不過效率要再測
09/22 17:25, 3F

09/22 17:25, 2年前 , 4F
恨PY
09/22 17:25, 4F
文章代碼(AID): #1b3LkLJC (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1b3LkLJC (Marginalman)