@@ -146,6 +146,60 @@ public:
146
146
};
147
147
```
148
148
149
+ ### **TypeScript**
150
+
151
+ ```ts
152
+ function movingCount(m: number, n: number, k: number): number {
153
+ const set = new Set();
154
+ const dfs = (y: number, x: number) => {
155
+ if (y === m || x === n || set.has(`${y},${x}`)) {
156
+ return;
157
+ }
158
+ let count = 0;
159
+ const str = `${y}${x}`;
160
+ for (const c of str) {
161
+ count += Number(c);
162
+ }
163
+ if (count <= k) {
164
+ set.add(`${y},${x}`);
165
+ dfs(y + 1, x);
166
+ dfs(y, x + 1);
167
+ }
168
+ };
169
+ dfs(0, 0);
170
+ return set.size;
171
+ }
172
+ ```
173
+
174
+ ### ** Rust**
175
+
176
+ ``` rust
177
+ use std :: collections :: {HashSet , VecDeque };
178
+
179
+ impl Solution {
180
+ pub fn moving_count (m : i32 , n : i32 , k : i32 ) -> i32 {
181
+ let mut deque = VecDeque :: new ();
182
+ let mut set = HashSet :: new ();
183
+ deque . push_back ([0 , 0 ]);
184
+ while let Some ([y , x ]) = deque . pop_front () {
185
+ if y < m && x < n && ! set . contains (& format! (" {},{}" , y , x )) {
186
+ let str = format! (" {}{}" , y , x );
187
+ let mut count = 0 ;
188
+ for c in str . chars () {
189
+ count += c . to_string (). parse :: <i32 >(). unwrap ();
190
+ }
191
+ if count <= k {
192
+ set . insert (format! (" {},{}" , y , x ));
193
+ deque . push_back ([y + 1 , x ]);
194
+ deque . push_back ([y , x + 1 ]);
195
+ }
196
+ }
197
+ }
198
+ set . len () as i32
199
+ }
200
+ }
201
+ ```
202
+
149
203
### ** ...**
150
204
151
205
```
0 commit comments