###### tags: `Weekly Contest` # Weekly Contest 389 ## [3083. Existence of a Substring in a String and Its Reverse](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse/) (<font color=#00B8A3>Easy</font>) 限制 : <ul> <li><code>1 <= s.length <= 100</code></li> <li><code>s consists only of lowercase English letters.</code></li> </ul> ### Solution 屬於比較爛的雙指針寫法。 #### 時間複雜度: $O(n^2)$ #### 空間複雜度: $O(n)$ 程式碼: ```c++= class Solution { public: bool isSubstringPresent(string s) { for(int i=0;i<s.size()-1;i++) { for(int j=s.size()-1;j>0;j--) { if(s[j] == s[i] && s[i + 1] == s[j - 1]) return true; } } return false; } }; ``` ## [3084. Count Substrings Starting and Ending with Given Character](https://leetcode.com/problems/count-substrings-starting-and-ending-with-given-character/) (<font color=#FFC011>Medium</font>) 限制 : <ul> <li><code>1 <= s.length <= 10<sup>5</sup></code></li> <li><code>s and c consist only of lowercase English letters.</code></li> </ul> ### Solution #### 時間複雜度: $O(n)$ #### 空間複雜度: $O(1)$ 程式碼: ```c++= class Solution { public: long long countSubstrings(string s, char c) { int charCount = 0; long long result = 0; for(int i=0;i<s.size();i++) { if (c == s[i]) { charCount++; result += charCount; } } return result; } }; ``` ## [3]()(<font color=#FFC011>Medium</font>) 限制 : <ul> <li><code>10<sup>4</sup></code></li> </ul> ### Solution #### 時間複雜度: $O()$ #### 空間複雜度: $O()$ 程式碼: ```c++= ``` ## [4]()(<font color=#FF375F>Hard</font>) 限制 : <ul> <li><code>10<sup>4</sup></code></li> </ul> ### Solution #### 時間複雜度: $O()$ #### 空間複雜度: $O()$ 程式碼: ```c++= ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up