精華區beta Marginalman 關於我們 聯絡資訊
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
blc: return s in t 09/22 17:23
Che31128: equal 09/22 17:23
blc: Python,不過效率要再測 09/22 17:25
Rushia: 恨PY 09/22 17:25