File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -109,13 +109,13 @@ Python3 Code:
109109``` py
110110class Solution :
111111 def shortestToChar (self , S : str , C : str ) -> List[int ]:
112- pre = - 10000
112+ pre = - 20000
113113 ans = []
114114
115115 for i in range (len (S)):
116116 if S[i] == C: pre = i
117117 ans.append(i - pre)
118- pre = 10000
118+ pre = 20000
119119 for i in range (len (S) - 1 , - 1 , - 1 ):
120120 if S[i] == C: pre = i
121121 ans[i] = min (ans[i], pre - i)
@@ -129,14 +129,14 @@ class Solution {
129129 public int [] shortestToChar (String S , char C ) {
130130 int N = S . length();
131131 int [] ans = new int [N ];
132- int prev = - 10000 ;
132+ int prev = - 20000 ;
133133
134134 for (int i = 0 ; i < N ; ++ i) {
135135 if (S . charAt(i) == C ) prev = i;
136136 ans[i] = i - prev;
137137 }
138138
139- prev = 10000 ;
139+ prev = 20000 ;
140140 for (int i = N - 1 ; i >= 0 ; -- i) {
141141 if (S . charAt(i) == C ) prev = i;
142142 ans[i] = Math . min(ans[i], prev - i);
@@ -154,12 +154,12 @@ class Solution {
154154public:
155155 vector<int > shortestToChar(string S, char C) {
156156 vector<int > ans(S.size(), 0);
157- int prev = -10000 ;
157+ int prev = -20000 ;
158158 for(int i = 0; i < S.size(); i ++){
159159 if(S[ i] == C) prev = i;
160160 ans[ i] = i - prev;
161161 }
162- prev = 10000 ;
162+ prev = 20000 ;
163163 for(int i = S.size() - 1; i >= 0; i --){
164164 if(S[ i] == C) prev = i;
165165 ans[ i] = min(ans[ i] , prev - i);
You can’t perform that action at this time.
0 commit comments