-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add solutions to lc problem: No.2083 (#4008)
No.2083.Substrings That Begin and End With the Same Letter
- Loading branch information
Showing
7 changed files
with
155 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ class Solution { | |
} | ||
return ans; | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
solution/2000-2099/2083.Substrings That Begin and End With the Same Letter/Solution.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* @param {string} s | ||
* @return {number} | ||
*/ | ||
var numberOfSubstrings = function (s) { | ||
const cnt = {}; | ||
let ans = 0; | ||
for (const c of s) { | ||
cnt[c] = (cnt[c] || 0) + 1; | ||
ans += cnt[c]; | ||
} | ||
return ans; | ||
}; |
12 changes: 12 additions & 0 deletions
12
solution/2000-2099/2083.Substrings That Begin and End With the Same Letter/Solution.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
impl Solution { | ||
pub fn number_of_substrings(s: String) -> i64 { | ||
let mut cnt = [0; 26]; | ||
let mut ans = 0_i64; | ||
for c in s.chars() { | ||
let idx = (c as u8 - b'a') as usize; | ||
cnt[idx] += 1; | ||
ans += cnt[idx]; | ||
} | ||
ans | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
solution/2000-2099/2083.Substrings That Begin and End With the Same Letter/Solution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function numberOfSubstrings(s: string): number { | ||
const cnt: Record<string, number> = {}; | ||
let ans = 0; | ||
for (const c of s) { | ||
cnt[c] = (cnt[c] || 0) + 1; | ||
ans += cnt[c]; | ||
} | ||
return ans; | ||
} |