From e1e368ca7a9c749946a51c53e2ebdf90c1895a1e Mon Sep 17 00:00:00 2001 From: Mhrooz Date: Sun, 26 Nov 2023 00:56:58 +0100 Subject: [PATCH] 828 pass --- 2699-231124/main.cpp | 7 +++- 828-231125-pass/main.cpp | 89 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 828-231125-pass/main.cpp diff --git a/2699-231124/main.cpp b/2699-231124/main.cpp index 38ae9c0..e295572 100644 --- a/2699-231124/main.cpp +++ b/2699-231124/main.cpp @@ -1,12 +1,15 @@ +//https://leetcode.com/problems/modify-graph-edge-weights/ #include using namespace std; class Solution{ public: vector> modifiedGraphEdges(int n, vector>& edges, int source, int destination, int target){ - + } -} +}; + int main(){ + int n; } \ No newline at end of file diff --git a/828-231125-pass/main.cpp b/828-231125-pass/main.cpp new file mode 100644 index 0000000..a48415e --- /dev/null +++ b/828-231125-pass/main.cpp @@ -0,0 +1,89 @@ +#include +using namespace std; + +class Solution{ +public: + int uniqueLetterString(string s){ + const int constraint_length = s.size() + 10; + const int ch_nums = 26; + const int first_char = (int)'A'; + + // store the distance, first is the distance to the previous charactor, second is the distance to the next char + pair ch_dist[constraint_length]; + //index store index from 1 + int index[ch_nums] = {}; + + // try to find the distance + for(int i = 0 ; i < s.size() ; i++){ + const int word_th = s[i] - first_char; + ch_dist[i + 1].first = i + 1 - index[word_th]; + if(index[word_th] != 0) + ch_dist[index[word_th]].second = i + 1 - index[word_th]; + index[word_th] = i + 1; + } + + for(int i = 0 ; i < ch_nums ; i++){ + if(index[i]!=0){ + ch_dist[index[i]].second = s.size() + 1 - index[i]; + // cout<