天池 在线编程 能否转换
生活随笔
收集整理的這篇文章主要介紹了
天池 在线编程 能否转换
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 1. 題目
- 2. 解題
1. 題目
給兩個字符串 S 和 T, 判斷 S 能不能通過刪除一些字母(包括0個)變成 T.
樣例1 輸入: S = "lintcode" 和 T = "lint" 輸出: true樣例2 輸入: S = "lintcode" 和 T = "ide" 輸出: true樣例3 輸入: S = "adda" and T = "aad" 輸出: false 解釋: 無論如何,你都不能通過刪除一個'd' 把 "adda" 變成 "aad"。https://tianchi.aliyun.com/oj/286614371019772507/338469151696950135
2. 解題
class Solution { public:/*** @param s: string S* @param t: string T* @return: whether S can convert to T*/bool canConvert(string &s, string &t) {// Write your code hereint n1 = s.size(), n2 = t.size();int i = 0, j = 0;while(i < n1 && j < n2){if(s[i] == t[j])i++,j++;elsei++;}return j==n2;} };8ms C++
我的CSDN博客地址 https://michael.blog.csdn.net/
長按或掃碼關注我的公眾號(Michael阿明),一起加油、一起學習進步!
總結
以上是生活随笔為你收集整理的天池 在线编程 能否转换的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode 1819. 序列中不同
- 下一篇: pypinyin 获取多音字的拼音组合