392. Is Subsequence

本文介绍了一种简单有效的方法来判断一个字符串是否为另一个字符串的子序列。通过双指针技术,该方法能在较短的时间内得出结论,适用于s较短(<=100),t可能很长(~500,000)的情况。
部署运行你感兴趣的模型镜像

内容:

Given a string s and a string t, check if s is subsequence of t.

You may assume that there is only lower case English letters in both s and tt is potentially a very long (length ~= 500,000) string, and sis a short string (<=100).

A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ace" is a subsequence of "abcde" while "aec" is not).

思路:

判断一个字符串是否是另一个字符串的子序列,如果s是t的子序列,t可以这样构成:在s字符串中的任意位置插入任意长度的字符串。

【思路】

1.维持两个字符串指针,分别指向s和t,如果当前字符相同,则指针都向后移动,否则只移动t的指针,直到s中出现的字符都在t中出现过了,我们可以判定s是t的子序列。代码如下:

public class Solution {
    public boolean isSubsequence(String s, String t) {
        int sindex = 0, tindex = 0;
        while(sindex < s.length() && tindex < t.length()) {
            if(s.charAt(sindex) == t.charAt(tindex)) {
                sindex++;
            }
            tindex++;
        }
        if(sindex == s.length()) return true;
        return false;
    }
}


您可能感兴趣的与本文相关的镜像

Anything-LLM

Anything-LLM

AI应用

AnythingLLM是一个全栈应用程序,可以使用商用或开源的LLM/嵌入器/语义向量数据库模型,帮助用户在本地或云端搭建个性化的聊天机器人系统,且无需复杂设置

CVE-2022-41741 A vulnerability in the module ngx_http_mp4_module might allow a local attacker to corrupt NGINX worker memory, resulting in its termination or potential other impact using a specially crafted audio or video file. The attack is only possible if an attacker can gain privileged access to the host running NGINX, place a specially crafted audio or video file within the webroot, and then trigger NGINX to process the specially crafted file. v3.1 v4.0 Base 7.0 7.3 CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H CVSS:4.0/AV:L/AC:L/AT:P/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N CVSS v4 Score: Base 7.3 Metric Value Comments Attack Vector Local An attacker must be able to access the vulnerable system with a local, interactive session. Attack Complexity Low No specialized conditions or advanced knowledge are required. Attack Requirements Present Multiple conditions that require target specific reconnaissance and preparation must be satisfied in order to achieve successful exploitation of this vulnerability. Privileges Required Low An attacker must be able to place a file within the web root to be processed by NGINX. User Interaction None No user interaction is required for an attacker to successfully exploit the vulnerability. Vulnerable System Confidentiality High The attacker could execute arbitrary code on the vulnerable system with elevated privileges. Vulnerable System Integrity High The attacker could execute arbitrary code on the vulnerable system with elevated privileges. Vulnerable System Availability High The attacker could execute arbitrary code on the vulnerable system with elevated privileges. Subsequent System Confidentiality None There is no impact to the subsequent system confidentiality. Subsequent System Integrity None There is no impact to the subsequent system integrity. Subsequent System Availability None There is no impact to the subsequent system availability. CVE-2020-3549 A vulnerability in the sftunnel functionality of Cisco Firepower Management Center (FMC) Software and Cisco Firepower Threat Defense (FTD) Software could allow an unauthenticated, remote attacker to obtain the device registration hash. The vulnerability is due to insufficient sftunnel negotiation protection during initial device registration. An attacker in a man-in-the-middle position could exploit this vulnerability by intercepting a specific flow of the sftunnel communication between an FMC device and an FTD device. A successful exploit could allow the attacker to decrypt and modify the sftunnel communication between FMC and FTD devices, allowing the attacker to modify configuration data sent from an FMC device to an FTD device or alert data sent from an FTD device to an FMC device. v3.1 v4.0 Base 8.1 CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H 7.7 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N Base + Threat 5.2 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:U CVSS v4 Score: Base + Threat 5.2 Metric Value Comments Attack Vector Network The vulnerable system is accessible from remote networks. Attack Complexity Low No specialized conditions or advanced knowledge are required. Attack Requirements Present An attacker must be on-path to be able to intercept communications between affected systems. Privileges Required None No privileges are required for an attacker to successfully exploit the vulnerability. User Interaction Passive A user must be logged in and using the application for traffic to be generated that an attacker could capture. Vulnerable System Confidentiality High An attacker could gain access to the system with a highly privileged user account. Vulnerable System Integrity High An attacker could gain access to the system with a highly privileged user account. Vulnerable System Availability High An attacker could gain access to the system with a highly privileged user account. Subsequent System Confidentiality None There is no impact to the vulnerable system confidentiality. Subsequent System Integrity None There is no impact to the vulnerable system integrity. Subsequent System Availability None There is no impact to the vulnerable system availability. Exploit Maturity Unreported There is no known proof-of-concept code or malicious exploitation of this vulnerability.
最新发布
07-09
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值