File tree Expand file tree Collapse file tree 5 files changed +138
-0
lines changed
solution/1400-1499/1436.Destination City Expand file tree Collapse file tree 5 files changed +138
-0
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,57 @@ var destCity = function (paths) {
154
154
};
155
155
```
156
156
157
+ ### ** TypeScript**
158
+
159
+ ``` ts
160
+ function destCity(paths : string [][]): string {
161
+ const set = new Set (paths .map (([a ]) => a ));
162
+ for (const [_, b] of paths ) {
163
+ if (! set .has (b )) {
164
+ return b ;
165
+ }
166
+ }
167
+ return ' ' ;
168
+ }
169
+ ```
170
+
171
+ ### ** Rust**
172
+
173
+ ``` rust
174
+ use std :: collections :: HashSet ;
175
+ impl Solution {
176
+ pub fn dest_city (paths : Vec <Vec <String >>) -> String {
177
+ let set = paths . iter (). map (| v | & v [0 ]). collect :: <HashSet <& String >>();
178
+ for path in paths . iter () {
179
+ if ! set . contains (& path [1 ]) {
180
+ return path [1 ]. clone ();
181
+ }
182
+ }
183
+ String :: new ()
184
+ }
185
+ }
186
+ ```
187
+
188
+ ### ** C**
189
+
190
+ ``` c
191
+ char *destCity (char *** paths, int pathsSize, int * pathsColSize) {
192
+ for (int i = 0; i < pathsSize; i++) {
193
+ int flag = 1;
194
+ for (int j = 0; j < pathsSize; j++) {
195
+ if (strcmp(paths[ i] [ 1 ] , paths[ j] [ 0 ] ) == 0) {
196
+ flag = 0;
197
+ break;
198
+ }
199
+ }
200
+ if (flag) {
201
+ return paths[ i] [ 1 ] ;
202
+ }
203
+ }
204
+ return NULL;
205
+ }
206
+ ```
207
+
157
208
### **...**
158
209
159
210
```
Original file line number Diff line number Diff line change @@ -138,6 +138,57 @@ var destCity = function (paths) {
138
138
};
139
139
```
140
140
141
+ ### ** TypeScript**
142
+
143
+ ``` ts
144
+ function destCity(paths : string [][]): string {
145
+ const set = new Set (paths .map (([a ]) => a ));
146
+ for (const [_, b] of paths ) {
147
+ if (! set .has (b )) {
148
+ return b ;
149
+ }
150
+ }
151
+ return ' ' ;
152
+ }
153
+ ```
154
+
155
+ ### ** Rust**
156
+
157
+ ``` rust
158
+ use std :: collections :: HashSet ;
159
+ impl Solution {
160
+ pub fn dest_city (paths : Vec <Vec <String >>) -> String {
161
+ let set = paths . iter (). map (| v | & v [0 ]). collect :: <HashSet <& String >>();
162
+ for path in paths . iter () {
163
+ if ! set . contains (& path [1 ]) {
164
+ return path [1 ]. clone ();
165
+ }
166
+ }
167
+ String :: new ()
168
+ }
169
+ }
170
+ ```
171
+
172
+ ### ** C**
173
+
174
+ ``` c
175
+ char *destCity (char *** paths, int pathsSize, int * pathsColSize) {
176
+ for (int i = 0; i < pathsSize; i++) {
177
+ int flag = 1;
178
+ for (int j = 0; j < pathsSize; j++) {
179
+ if (strcmp(paths[ i] [ 1 ] , paths[ j] [ 0 ] ) == 0) {
180
+ flag = 0;
181
+ break;
182
+ }
183
+ }
184
+ if (flag) {
185
+ return paths[ i] [ 1 ] ;
186
+ }
187
+ }
188
+ return NULL;
189
+ }
190
+ ```
191
+
141
192
### **...**
142
193
143
194
```
Original file line number Diff line number Diff line change
1
+ char * destCity (char * * * paths , int pathsSize , int * pathsColSize ) {
2
+ for (int i = 0 ; i < pathsSize ; i ++ ) {
3
+ int flag = 1 ;
4
+ for (int j = 0 ; j < pathsSize ; j ++ ) {
5
+ if (strcmp (paths [i ][1 ], paths [j ][0 ]) == 0 ) {
6
+ flag = 0 ;
7
+ break ;
8
+ }
9
+ }
10
+ if (flag ) {
11
+ return paths [i ][1 ];
12
+ }
13
+ }
14
+ return NULL ;
15
+ }
Original file line number Diff line number Diff line change
1
+ use std:: collections:: HashSet ;
2
+ impl Solution {
3
+ pub fn dest_city ( paths : Vec < Vec < String > > ) -> String {
4
+ let set = paths. iter ( ) . map ( |v| & v[ 0 ] ) . collect :: < HashSet < & String > > ( ) ;
5
+ for path in paths. iter ( ) {
6
+ if !set. contains ( & path[ 1 ] ) {
7
+ return path[ 1 ] . clone ( ) ;
8
+ }
9
+ }
10
+ String :: new ( )
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ function destCity ( paths : string [ ] [ ] ) : string {
2
+ const set = new Set ( paths . map ( ( [ a ] ) => a ) ) ;
3
+ for ( const [ _ , b ] of paths ) {
4
+ if ( ! set . has ( b ) ) {
5
+ return b ;
6
+ }
7
+ }
8
+ return '' ;
9
+ }
You can’t perform that action at this time.
0 commit comments