# 2083. Substrings That Begin and End With the Same Letter ###### tags: `Leetcode` `Medium` `HashMap` Link: https://leetcode.com/problems/substrings-that-begin-and-end-with-the-same-letter/description/ ## Code ```java= class Solution { public long numberOfSubstrings(String s) { long ans = 0; int[] cnt = new int[26]; for(int i=0; i<s.length(); i++){ cnt[s.charAt(i)-'a']++; ans += cnt[s.charAt(i)-'a']; } return ans; } } ```