Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ccf428e

Browse files
updating all READMEs
1 parent ce7f8d2 commit ccf428e

File tree

16 files changed

+1110
-92
lines changed

16 files changed

+1110
-92
lines changed

‎.dev/logs.json

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@
137137
}
138138
},
139139
"28": {
140-
"len": 0,
141-
"sols": {}
140+
"len": 2,
141+
"sols": {
142+
"find_the_index_of_the_first_ccurrence_in_a_string.rs": "12556d8e491c54b20196b5a876751be0f5b5327b620a2608a67675b19477def0"
143+
}
142144
},
143145
"29": {
144146
"len": 0,
@@ -3926,7 +3928,8 @@
39263928
"912": {
39273929
"len": 3,
39283930
"sols": {
3929-
"sort_an_array.go": "6c1d42703394ec5fdc2c84b9104e3d421203cbe7e8e2f1a50735a8de6a62fa0a"
3931+
"sort_an_array.go": "6c1d42703394ec5fdc2c84b9104e3d421203cbe7e8e2f1a50735a8de6a62fa0a",
3932+
"sort_an_array.rs": "c2610f7828436fefba02cb4b33fb170612f18d666d0885004a598ebc5128fcff"
39303933
}
39313934
},
39323935
"913": {
@@ -6352,8 +6355,10 @@
63526355
"sols": {}
63536356
},
63546357
"1512": {
6355-
"len": 0,
6356-
"sols": {}
6358+
"len": 2,
6359+
"sols": {
6360+
"number_of_good_pairs.rs": "003d19f133a9d31e078de05ddb7e5a0cbe39626a3f4a53e1d7dc47f0ef623cad"
6361+
}
63576362
},
63586363
"1513": {
63596364
"len": 0,
@@ -6996,8 +7001,10 @@
69967001
"sols": {}
69977002
},
69987003
"1672": {
6999-
"len": 0,
7000-
"sols": {}
7004+
"len": 2,
7005+
"sols": {
7006+
"richest_customer_wealth.rs": "fef21e52b9d3406ed262289dbab2b86f4d9b5df0c7244e240fa48b244ffe8906"
7007+
}
70017008
},
70027009
"1673": {
70037010
"len": 0,
@@ -7064,8 +7071,10 @@
70647071
"sols": {}
70657072
},
70667073
"1689": {
7067-
"len": 0,
7068-
"sols": {}
7074+
"len": 2,
7075+
"sols": {
7076+
"partitioning_into_minimum_number_of_deci_binary_numbers.rs": "c3f823f06625aeaf855cc2d6c6ae001e7da1e78ab41a14d5d863def70823332e"
7077+
}
70697078
},
70707079
"1690": {
70717080
"len": 0,
@@ -8358,8 +8367,10 @@
83588367
"sols": {}
83598368
},
83608369
"2011": {
8361-
"len": 0,
8362-
"sols": {}
8370+
"len": 2,
8371+
"sols": {
8372+
"final_value_of_variables_after_performing_operations.rs": "5621285f0c0ae83211e5476a20a734952c02a2ba1536b0827cf9299370f472d4"
8373+
}
83638374
},
83648375
"2012": {
83658376
"len": 0,
@@ -8770,8 +8781,10 @@
87708781
"sols": {}
87718782
},
87728783
"2114": {
8773-
"len": 0,
8774-
"sols": {}
8784+
"len": 2,
8785+
"sols": {
8786+
"max_num_of_words_found_in_a_sentence.rs": "ffd65aec1202f5fc2df491b544fdd1bd1ae8aa040d559f8aaccc5b74c7fa4d3b"
8787+
}
87758788
},
87768789
"2115": {
87778790
"len": 0,
@@ -9256,8 +9269,10 @@
92569269
"sols": {}
92579270
},
92589271
"2235": {
9259-
"len": 0,
9260-
"sols": {}
9272+
"len": 2,
9273+
"sols": {
9274+
"add_two_integers.rs": "d34d53238dc7e5b2018456ea68b14655453bce7cfd3637246630230667913fd0"
9275+
}
92619276
},
92629277
"2236": {
92639278
"len": 2,
@@ -9902,8 +9917,10 @@
99029917
"sols": {}
99039918
},
99049919
"2396": {
9905-
"len": 0,
9906-
"sols": {}
9920+
"len": 2,
9921+
"sols": {
9922+
"strictly_palindromic_number.rs": "d06103c5b46fa0414f8ff13355a2e44fc23790399ce0ce4aa1994d58434518d6"
9923+
}
99079924
},
99089925
"2397": {
99099926
"len": 0,
@@ -9970,8 +9987,10 @@
99709987
"sols": {}
99719988
},
99729989
"2413": {
9973-
"len": 0,
9974-
"sols": {}
9990+
"len": 2,
9991+
"sols": {
9992+
"smallest_even_multiple.rs": "84ec13c6cb1e0582cb96f031c3ff64f139cd822617e395af0a81d648727b9d1b"
9993+
}
99759994
},
99769995
"2414": {
99779996
"len": 0,
@@ -10096,8 +10115,10 @@
1009610115
"sols": {}
1009710116
},
1009810117
"2444": {
10099-
"len": 0,
10100-
"sols": {}
10118+
"len": 2,
10119+
"sols": {
10120+
"count_subarrays_with_fixed_bounds.rs": "70b1766a935a16a3eab48337fca22806fdf31583c04d2b3b56603a9aef987b6d"
10121+
}
1010110122
},
1010210123
"2445": {
1010310124
"len": 0,
@@ -10356,5 +10377,11 @@
1035610377
"2508": {
1035710378
"len": 0,
1035810379
"sols": {}
10380+
},
10381+
"2574": {
10382+
"len": 2,
10383+
"sols": {
10384+
"left_and_right_sum_differences.rs": "e82dccb7152fb1bd9268100531ead21bca1f7bcdb6cc688e506949f6046f4774"
10385+
}
1035910386
}
1036010387
}

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
[**_Rejection Sampling_**][rejection sampling]   
9696
[**_Biconnected Component_**][biconnected component]
9797

98-
### **Total Problems Solved: _156_**
98+
### **Total Problems Solved: _167_**
9999

100100
---
101101

‎TOPICWISE.md

Lines changed: 105 additions & 69 deletions
Large diffs are not rendered by default.

‎docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ It might take some time to reflect changes from the repository.
103103
[**_Rejection Sampling_**][rejection sampling]   
104104
[**_Biconnected Component_**][biconnected component]
105105

106-
### **Total Problems Solved: _156_**
106+
### **Total Problems Solved: _167_**
107107

108108
## Contributors
109109

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# 28. Find the Index of the First Occurrence in a String [![share]](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/)
2+
3+
![][medium]
4+
5+
## Problem Statement
6+
7+
<p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
8+
<p> </p>
9+
<p><strong class="example">Example 1:</strong></p>
10+
11+
```
12+
Input: haystack = "sadbutsad", needle = "sad"
13+
Output: 0
14+
Explanation: "sad" occurs at index 0 and 6.
15+
The first occurrence is at index 0, so we return 0.
16+
```
17+
18+
<p><strong class="example">Example 2:</strong></p>
19+
20+
```
21+
Input: haystack = "leetcode", needle = "leeto"
22+
Output: -1
23+
Explanation: "leeto" did not occur in "leetcode", so we return -1.
24+
```
25+
26+
<p> </p>
27+
<p><strong>Constraints:</strong></p>
28+
<ul>
29+
<li><code>1 &lt;= haystack.length, needle.length &lt;= 10<sup>4</sup></code></li>
30+
<li><code>haystack</code> and <code>needle</code> consist of only lowercase English characters.</li>
31+
</ul>
32+
33+
## Solutions
34+
35+
### [_Rust_](find_the_index_of_the_first_ccurrence_in_a_string.rs)
36+
37+
```rs [Rust]
38+
impl Solution {
39+
pub fn str_str(haystack: String, needle: String) -> i32 {
40+
let (m, n) = (haystack.len(), needle.len());
41+
42+
if m < n {
43+
return -1;
44+
}
45+
46+
// iterate over the haystack from 0 to m - n
47+
// because the needle can't be longer than the haystack
48+
for i in 0..=m - n {
49+
if haystack[i..i + n] == needle {
50+
return i as i32;
51+
}
52+
}
53+
54+
-1
55+
}
56+
}
57+
58+
```
59+
60+
### [_..._]()
61+
62+
```
63+
64+
```
65+
66+
<!----------------------------------{ link }--------------------------------->
67+
68+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
69+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
70+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
71+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# 1512. Number of Good Pairs [![share]](https://leetcode.com/problems/number-of-good-pairs/)
2+
3+
![][easy]
4+
5+
## Problem Statement
6+
7+
<p>Given an array of integers <code>nums</code>, return <em>the number of <strong>good pairs</strong></em>.</p>
8+
<p>A pair <code>(i, j)</code> is called <em>good</em> if <code>nums[i] == nums[j]</code> and <code>i</code> &lt; <code>j</code>.</p>
9+
<p> </p>
10+
<p><strong class="example">Example 1:</strong></p>
11+
12+
```
13+
Input: nums = [1,2,3,1,1,3]
14+
Output: 4
15+
Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.
16+
```
17+
18+
<p><strong class="example">Example 2:</strong></p>
19+
20+
```
21+
Input: nums = [1,1,1,1]
22+
Output: 6
23+
Explanation: Each pair in the array are good.
24+
```
25+
26+
<p><strong class="example">Example 3:</strong></p>
27+
28+
```
29+
Input: nums = [1,2,3]
30+
Output: 0
31+
```
32+
33+
<p> </p>
34+
<p><strong>Constraints:</strong></p>
35+
<ul>
36+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
37+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
38+
</ul>
39+
40+
<details>
41+
<summary>
42+
43+
#### _Click to open Hints_
44+
45+
</summary>
46+
47+
- Count how many times each number appears. If a number appears n times, then n \* (n – 1) // 2 good pairs can be made with this number.
48+
49+
</details>
50+
51+
## Solutions
52+
53+
### [_Rust_](number_of_good_pairs.rs)
54+
55+
```rs [Rust]
56+
impl Solution {
57+
pub fn num_identical_pairs(nums: Vec<i32>) -> i32 {
58+
let mut count = 0;
59+
let mut map = std::collections::HashMap::new();
60+
61+
for num in nums {
62+
let entry = map.entry(num).or_insert(0);
63+
count += *entry;
64+
*entry += 1;
65+
}
66+
67+
count
68+
}
69+
}
70+
71+
```
72+
73+
### [_..._]()
74+
75+
```
76+
77+
```
78+
79+
<!----------------------------------{ link }--------------------------------->
80+
81+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
82+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
83+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
84+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /