Skip to content

Commit 7778f73

Browse files
Update README.md
1 parent ceb14c1 commit 7778f73

File tree

1 file changed

+106
-94
lines changed

1 file changed

+106
-94
lines changed

top 150/README.md

Lines changed: 106 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
<details><!--page starts-->
2+
<summary><strong>MY LEETCODE SOLUTIONS:</strong></summary>
3+
<br>
14

5+
<!--modules-->
6+
<!--module 3 starts-->
27
<details>
3-
<summary> <strong>3. Longest Substring Without Repeating Characters</strong> </summary>
4-
<br>
8+
<summary> <strong>3. Longest Substring Without Repeating Characters</strong> </summary>
9+
510
Given a string s, find the length of the longest
611
substring
712
without repeating characters.
13+
814
```typescript
915
Example 1:
1016
Input: s = "abcabcbb"
@@ -21,7 +27,11 @@ Input: s = "pwwkew"
2127
Output: 3
2228
Explanation: The answer is "wke", with the length of 3.
2329
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
30+
2431
```
32+
<!--module 3 code-->
33+
<details>
34+
<summary><strong>See solution</strong></summary>
2535

2636
```typescript
2737
function lengthOfLongestSubstring(s: string): number {
@@ -46,12 +56,15 @@ function lengthOfLongestSubstring(s: string): number {
4656
return longesSubstring;
4757
}
4858
```
49-
</details>
5059

51-
##### 4. Median of Two Sorted Arrays
52-
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
60+
</details><!--module 3 code ends-->
61+
</details><!--module 3 ends-->
5362

54-
The overall run time complexity should be O(log (m+n)).
63+
<details>
64+
<summary> <strong>4. Median of Two Sorted Arrays</strong> </summary>
65+
66+
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
67+
5568
```typescript
5669
Example 1:
5770
Input: nums1 = [1,3], nums2 = [2]
@@ -72,6 +85,10 @@ nums2.length == n
7285
1 <= m + n <= 2000
7386
-106 <= nums1[i], nums2[i] <= 106
7487
```
88+
<!--module 4 code-->
89+
<details>
90+
<summary><strong>See solution</strong></summary>
91+
7592
```typescript
7693
function findMedianSortedArrays(nums1:number[], nums2:number[]):number {
7794
const totalLength:number = nums1.length + nums2.length;
@@ -100,53 +117,18 @@ function findMedianSortedArrays(nums1:number[], nums2:number[]):number {
100117

101118
```
102119

103-
104-
105-
```typescript
106-
function findMedianSortedArrays(nums1: number[], nums2: number[]): number {
107-
if (nums1.length > nums2.length) {
108-
[nums1, nums2] = [nums2, nums1]; // swap to ensure nums1 is smaller
109-
}
110-
111-
const m = nums1.length;
112-
const n = nums2.length;
113-
let iMin = 0;
114-
let iMax = m;
115-
const mid = Math.floor((m + n + 1) / 2);
116-
117-
while (iMin <= iMax) {
118-
const i = Math.floor((iMin + iMax) / 2);
119-
const j = mid - i;
120-
121-
if (i < iMax && nums2[j-1] > nums1[i]) {
122-
iMin = i + 1;
123-
} else if (i > iMin && nums1[i-1] > nums2[j]) {
124-
iMax = i - 1;
125-
} else {
126-
const leftMax = i === 0 ? nums2[j-1]
127-
: j === 0 ? nums1[i-1]
128-
: Math.max(nums1[i-1], nums2[j-1]);
129-
130-
if ((m + n) % 2 === 1) {
131-
return leftMax;
132-
}
133-
134-
const rightMin = i === m ? nums2[j]
135-
: j === n ? nums1[i]
136-
: Math.min(nums1[i], nums2[j]);
137-
138-
return (leftMax + rightMin) / 2;
139-
}
140-
}
141-
}
142-
```
143-
30-31.03.2023:
144-
##### 5. Longest Palindromic Substring
145-
Given a string s, return the longest palindromic substring in s.
146-
147-
A substring is a contiguous non-empty sequence of characters within a string.
120+
</details><!--module 4 code ends-->
121+
</details><!--module 4 ends-->
122+
123+
124+
125+
126+
<details>
127+
<summary> <strong>5. Longest Palindromic Substring</strong> </summary>
128+
Given a string s, return the longest palindromic substring in s.
129+
A substring is a contiguous non-empty sequence of characters within a string.
130+
148131
```typescript
149-
150132
Example 1:
151133
Input: s = "babad"
152134
Output: "bab"
@@ -157,15 +139,15 @@ Example 2:
157139
Input: s = "cbbd"
158140
Output: "bb"
159141

160-
```
161-
162-
```typescript
163-
EConstraints:
142+
Constraints:
164143

165144
1 <= s.length <= 1000
166145
s consist of only digits and English letters.
167-
168146
```
147+
<!--module 5 code-->
148+
<details>
149+
<summary><strong>See solution</strong></summary>
150+
169151
```typescript
170152
function longestPalindrome(s:string):string {
171153

@@ -199,11 +181,18 @@ function expandFromCenter(s:string,L:number,R:number){//return the length
199181
return s.substring(start,end+1);//output [start,end]
200182
}
201183
```
202-
31.03-01.04.2023:
203-
##### 7.Reverse Integer
184+
185+
</details><!--module 5 code ends-->
186+
</details><!--module 5 ends-->
187+
188+
189+
190+
<details>
191+
<summary> <strong>7.Reverse Integer</strong> </summary>
204192
Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.
205-
###### Assume the environment does not allow you to store 64-bit integers (signed or unsigned).
206-
```example
193+
Assume the environment does not allow you to store 64-bit integers (signed or unsigned).
194+
195+
```typescript
207196
Example 1:
208197
Input: x = 123
209198
Output: 321
@@ -219,8 +208,11 @@ Output: 21
219208

220209
Constraints:
221210
-231 <= x <= 231 - 1
222-
223211
```
212+
<!--module 7 code-->
213+
<details>
214+
<summary><strong>See solution</strong></summary>
215+
224216
```typescript
225217
function reverse(x:number):number {
226218
let reversed:number = 0;
@@ -240,28 +232,45 @@ function reverse(x:number):number {
240232

241233
}
242234
```
243-
01.04.2023:
244-
##### 8. String to Integer (atoi)
245-
Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).
246-
247-
The algorithm for myAtoi(string s) is as follows:
248-
249-
Read in and ignore any leading whitespace.
250-
Check if the next character (if not already at the end of the string) is '-' or '+'. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present.
251-
Read in next the characters until the next non-digit character or the end of the input is reached. The rest of the string is ignored.
252-
Convert these digits into an integer (i.e. "123" -> 123, "0032" -> 32). If no digits were read, then the integer is 0. Change the sign as necessary (from step 2).
253-
If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then clamp the integer so that it remains in the range. Specifically, integers less than -231 should be clamped to -231, and integers greater than 231 - 1 should be clamped to 231 - 1.
254-
Return the integer as the final result.
255-
256-
###### Note:
257-
<ul>
258-
<li>Only the space character ' ' is considered a whitespace character.</li>
259-
<li>Do not ignore any characters other than the leading whitespace or the rest of the string after the digits.</li>
260-
</ul>
261-
262235

236+
</details><!--module 7 code ends-->
237+
</details><!--module 7 ends-->
238+
239+
240+
241+
242+
243+
244+
245+
246+
247+
<details>
248+
<summary> <strong>8. String to Integer (atoi)</strong> </summary>
249+
Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).
263250

264-
```example
251+
The algorithm for <strong>myAtoi(string s)</strong> is as follows:
252+
253+
Read in and ignore any leading whitespace.
254+
255+
Check if the next character (if not already at the end of the string) is '-' or '+'. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present.
256+
257+
Read in next the characters until the next non-digit character or the end of the input is reached. The rest of the string is ignored.
258+
259+
260+
Convert these digits into an integer (i.e. "123" -> 123, "0032" -> 32). If no digits were read, then the integer is 0. Change the sign as necessary (from step 2).
261+
262+
If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then clamp the integer so that it remains in the range. Specifically, integers less than -231 should be clamped to -231, and integers greater than 231 - 1 should be clamped to 231 - 1.
263+
264+
Return the integer as the final result.
265+
266+
267+
Note:
268+
<ul>
269+
<li>Only the space character ' ' is considered a whitespace character.</li>
270+
<li>Do not ignore any characters other than the leading whitespace or the rest of the string after the digits.</li>
271+
</ul>
272+
273+
```typescript
265274

266275
Example 1:
267276
Input: s = "42"
@@ -302,18 +311,21 @@ Step 3: "4193 with words" ("4193" is read in; reading stops because the next cha
302311
The parsed integer is 4193.
303312
Since 4193 is in the range [-231, 231 - 1], the final result is 4193.
304313
```
305-
```typescript
306-
307-
```
308-
309-
310-
311-
312-
314+
![image](https://user-images.githubusercontent.com/122405130/229276804-1c7a4ad6-74d2-49af-94a9-b231c80d05f3.png)
313315

316+
<!--module 8 code-->
317+
<details>
318+
<summary><strong>See solution</strong></summary>
314319

320+
```typescript
321+
!!!!!!!!!!!!!
322+
```
315323

316-
<!-- ##### learning compilation ts in vs code
317-
![image](https://user-images.githubusercontent.com/122405130/227340833-ab31e6fc-ff18-400d-a2f6-5aaf1cbab502.png)
318-
![image](https://user-images.githubusercontent.com/122405130/227340870-af539c7f-2488-496a-9226-942bbe89f1d1.png)
319-
-->
324+
</details><!--module 8 code ends-->
325+
</details><!--module 8 ends-->
326+
327+
328+
329+
330+
331+
</details>

0 commit comments

Comments
 (0)