File tree 2 files changed +44
-0
lines changed
2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def shortestWay (self , source : str , target : str ) -> int :
3
+ s = t = output = 0
4
+
5
+ while t < len (target ) :
6
+ loop = len (source )
7
+
8
+ while loop >= 0 and source [s ] != target [t ] :
9
+ s += 1
10
+ loop -= 1
11
+ if s >= len (source ) :
12
+ output += 1
13
+ s -= len (source )
14
+
15
+ if source [s ] != target [t ] :
16
+ return - 1
17
+
18
+ s += 1
19
+ t += 1
20
+ if s >= len (source ) :
21
+ output += 1
22
+ s -= len (source )
23
+
24
+ if s > 0 :
25
+ output += 1
26
+
27
+ return output
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def shortestWay (self , source : str , target : str ) -> int :
3
+ s = output = 0
4
+
5
+ for t in target :
6
+ for _ in repeat (None , len (source )) :
7
+ if source [s ] == t :
8
+ break
9
+ s = (s + 1 ) % len (source )
10
+ output += 1
11
+
12
+ if source [s ] != t :
13
+ return - 1
14
+ output += 1
15
+ s = (s + 1 ) % len (source )
16
+
17
+ return ceil (output / len (source ))
You can’t perform that action at this time.
0 commit comments