Skip to content

Commit 0016334

Browse files
committed
Runtime: 11 ms (Top 11.73%) | Memory: 6.7 MB (Top 59.28%)
1 parent 09af5b5 commit 0016334

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 11 ms (Top 11.73%) | Memory: 6.7 MB (Top 59.28%)
12
class Solution {
23
public:
34
vector<int> shortestToChar(string s, char c) {
@@ -8,17 +9,17 @@ class Solution {
89
int mins;
910
for(int i=0;i<s.length();i++){
1011
if(s[i]==c)
11-
//storing all the c character location i.e 'e' in sk i.e [3,5,6,11]
12+
//storing all the c character location i.e 'e' in sk i.e [3,5,6,11]
1213
sk.push_back(i);
1314
}
1415
for(int i=0;i<s.length();i++){
1516
for(int j=0;j<sk.size();j++){
16-
//now subtracting every i value with all value of character locations and storing the minimum in res vector.
17-
17+
//now subtracting every i value with all value of character locations and storing the minimum in res vector.
18+
1819
mins=abs(sk[j]-i);
1920
temp.push_back(mins);
2021
}
21-
//in first iteration [3-0=3,5-0=5,6-0=6,11-0=0] so removing the minimum elemnet from this that is 3 and stroing is res.
22+
//in first iteration [3-0=3,5-0=5,6-0=6,11-0=0] so removing the minimum elemnet from this that is 3 and stroing is res.
2223
int min=temp[0];
2324
for(auto i:temp){
2425
if(i<min){
@@ -27,9 +28,9 @@ class Solution {
2728
}
2829
res.push_back(min);
2930
temp.clear();
30-
31+
3132
}
3233

3334
return res;
3435
}
35-
};
36+
};

0 commit comments

Comments
 (0)