Skip to content

Commit 24f0086

Browse files
committed
Update 821.shortest-distance-to-a-character.md
1 parent d159669 commit 24f0086

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

problems/821.shortest-distance-to-a-character.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ Python3 Code:
109109
```py
110110
class 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 {
154154
public:
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);

0 commit comments

Comments
 (0)