Skip to content

Commit 81a036d

Browse files
committed
all complexity style chnaged
1 parent 0b47bf6 commit 81a036d

7 files changed

+28
-28
lines changed

dsa-solutions/lc-solutions/0000-0099/0004-Median-of-two-Sorted-Array.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def findMedianSortedArrays(nums1, nums2):
7676
return (merged[n // 2 - 1] + merged[n // 2]) / 2.0
7777
```
7878

79-
#### Approach 2: Binary Search (O(log(min(m, n))))
79+
#### Approach 2: Binary Search $(O(log(min(m, n))))$
8080

8181
**Intuition:**
8282
To achieve $O(log(min(m, n)))$ complexity, use binary search on the smaller array. The goal is to find a partition where the left half of both arrays combined is less than or equal to the right half.

dsa-solutions/lc-solutions/0000-0099/0005-Longest-palindrome-substring.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def longestPalindrome(s: str) -> str:
7070
```
7171

7272
### Complexity Analysis
73-
- **Time complexity**: `O(n^3)` - We check each substring, and checking each substring takes `O(n)` time.
74-
- **Space complexity**: `O(1)` - We use a constant amount of extra space.
73+
- **Time complexity**: $O(n^3)$ - We check each substring, and checking each substring takes $O(n)$ time.
74+
- **Space complexity**: $O(1)$ - We use a constant amount of extra space.
7575

7676
### Approach 2: Dynamic Programming
7777

@@ -112,8 +112,8 @@ def longestPalindrome(s: str) -> str:
112112
```
113113

114114
### Complexity Analysis
115-
- **Time complexity**: `O(n^2)` - We fill an `n * n` table.
116-
- **Space complexity**: `O(n^2)` - We use an `n * n` table to store the DP results.
115+
- **Time complexity**: $O(n^2)$ - We fill an `n * n` table.
116+
- **Space complexity**: $O(n^2)$ - We use an `n * n` table to store the DP results.
117117

118118
### Approach 3: Expand From Centers
119119

@@ -148,8 +148,8 @@ def longestPalindrome(s: str) -> str:
148148
```
149149

150150
### Complexity Analysis
151-
- **Time complexity**: `O(n^2)` - We expand around each center, which takes `O(n)` time.
152-
- **Space complexity**: `O(1)` - We use a constant amount of extra space.
151+
- **Time complexity**: $O(n^2)$ - We expand around each center, which takes $O(n)$ time.
152+
- **Space complexity**: $O(1)$ - We use a constant amount of extra space.
153153

154154
### Approach 4: Manacher's Algorithm
155155

@@ -185,8 +185,8 @@ def longestPalindrome(s: str) -> str:
185185
```
186186

187187
### Complexity Analysis
188-
- **Time complexity**: `O(n)` - Manacher's algorithm runs in linear time.
189-
- **Space complexity**: `O(n)` - We use an array of length `n` to store the lengths of palindromes.
188+
- **Time complexity**: $O(n)$ - Manacher's algorithm runs in linear time.
189+
- **Space complexity**: $O(n)$ - We use an array of length `n` to store the lengths of palindromes.
190190

191191
### Conclusion
192192
We discussed four approaches to solve the "Longest Palindromic Substring" problem, each with varying complexities and trade-offs. The dynamic programming and center expansion approaches provide a good balance of simplicity and efficiency for practical use cases, while Manacher's algorithm offers the optimal theoretical performance.

dsa-solutions/lc-solutions/0000-0099/0006-ZigZag-Conversion.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,24 +204,24 @@ class Solution:
204204

205205
#### Approach 1: Iterative Approach
206206

207-
- **Time Complexity**: O(n), where n is the length of the input string `s`. We iterate through the entire string once.
208-
- **Space Complexity**: O(n), where n is the length of the input string `s`. We use a StringBuilder to store the output.
207+
- **Time Complexity**: $O(n)$, where n is the length of the input string `s`. We iterate through the entire string once.
208+
- **Space Complexity**: $O(n)$, where n is the length of the input string `s`. We use a StringBuilder to store the output.
209209

210210
#### Approach 2: Using StringBuilder Rows
211211

212-
- **Time Complexity**: O(n), where n is the length of the input string `s`. We iterate through the entire string once to fill the rows of the StringBuilder.
213-
- **Space Complexity**: O(n), where n is the length of the input string `s`. We use a StringBuilder to store the output.
212+
- **Time Complexity**: $O(n)$, where n is the length of the input string `s`. We iterate through the entire string once to fill the rows of the StringBuilder.
213+
- **Space Complexity**:$O(n)$, where n is the length of the input string `s`. We use a StringBuilder to store the output.
214214

215215
#### Approach 3: Direct Construction
216216

217-
- **Time Complexity**: O(n), where n is the length of the input string `s`. We iterate through the entire string once to construct the output string.
218-
- **Space Complexity**: O(n), where n is the length of the input string `s`. We use a StringBuilder to store the output.
217+
- **Time Complexity**: $O(n)$, where n is the length of the input string `s`. We iterate through the entire string once to construct the output string.
218+
- **Space Complexity**: $O(n)$, where n is the length of the input string `s`. We use a StringBuilder to store the output.
219219

220220
#### Approach 4: Using Mathematical Formula
221221

222-
- **Time Complexity**: O(n), where n is the length of the input string `s`. We iterate through the entire string once to construct the output string.
223-
- **Space Complexity**: O(n), where n is the length of the input string `s`. We use a StringBuilder to store the output.
222+
- **Time Complexity**: $O(n)$, where n is the length of the input string `s`. We iterate through the entire string once to construct the output string.
223+
- **Space Complexity**: $O(n)$, where n is the length of the input string `s`. We use a StringBuilder to store the output.
224224

225225
### Conclusion
226226

227-
We explored four different approaches to solve the Zigzag Conversion problem, each offering a unique perspective and trade-offs in terms of simplicity and efficiency. All four approaches have a linear time complexity of O(n), where n is the length of the input string `s`. The space complexity varies slightly among the approaches but remains linear in terms of the input size.
227+
We explored four different approaches to solve the Zigzag Conversion problem, each offering a unique perspective and trade-offs in terms of simplicity and efficiency. All four approaches have a linear time complexity of $O(n)$, where n is the length of the input string `s`. The space complexity varies slightly among the approaches but remains linear in terms of the input size.

dsa-solutions/lc-solutions/0000-0099/0007-Reverse-Integers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ class Solution:
155155

156156
### Complexity Analysis
157157

158-
- **Time Complexity**: O(log(x)). There are roughly log10(x) digits in `x`.
159-
- **Space Complexity**: O(1).
158+
- **Time Complexity**: $O(log(x))$. There are roughly log10(x) digits in `x`.
159+
- **Space Complexity**: $O(1)$.
160160

161161
### Conclusion
162162

dsa-solutions/lc-solutions/0000-0099/0008-String-to-Integer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ class Solution {
139139

140140
### Complexity Analysis
141141

142-
- **Time Complexity**: O(n), where n is the length of the string `s`.
143-
- **Space Complexity**: O(1), due to the constant number of variables used.
142+
- **Time Complexity**: $O(n)$, where n is the length of the string `s`.
143+
- **Space Complexity**: $O(1)$, due to the constant number of variables used.
144144

145145
## Conclusion
146146

dsa-solutions/lc-solutions/0000-0099/0009-Palindrome-number.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@ class Solution:
225225

226226
### Approach 1: Reversing the Entire Number
227227

228-
- **Time Complexity**: O(log10(x)), where x is the input number.
229-
- **Space Complexity**: O(1).
228+
- **Time Complexity**: $O(log10(x))$, where x is the input number.
229+
- **Space Complexity**: $O(1)$.
230230

231231
### Approach 2: Reversing Half of the Number
232232

233-
- **Time Complexity**: O(log10(x)), where x is the input number.
234-
- **Space Complexity**: O(1).
233+
- **Time Complexity**: $O(log10(x))$, where x is the input number.
234+
- **Space Complexity**: $O(1)$.
235235

236236
## Conclusion
237237

dsa-solutions/lc-solutions/0000-0099/0010-Regular-Expression-Matching.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,10 @@ class Solution:
220220
```
221221
Complexity Analysis
222222
Time Complexity
223-
Let T, P be the lengths of the text and the pattern respectively. The work for every call to dp(i, j) for i=0,...,T; j=0,...,P is done once, and it is O(1) work. Hence, the time complexity is O(TP).
223+
Let T, P be the lengths of the text and the pattern respectively. The work for every call to dp(i, j) for i=0,...,T; j=0,...,P is done once, and it is $O(1)$ work. Hence, the time complexity is $O(TP)$.
224224

225225
Space Complexity
226-
The only memory we use is the O(TP) boolean entries in our cache. Hence, the space complexity is O(TP)
226+
The only memory we use is the $O(TP)$ boolean entries in our cache. Hence, the space complexity is $O(TP)$
227227

228228

229229
Now, just as you asked, the last part should include the summary and links to the problem, solution, and profile. Let's add that:

0 commit comments

Comments
 (0)