File tree 4 files changed +104
-0
lines changed
lcci/01.09.String Rotation
4 files changed +104
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,55 @@ func isFlipedString(s1 string, s2 string) bool {
68
68
}
69
69
```
70
70
71
+ ### ** TypeScript**
72
+
73
+ ``` ts
74
+ function isFlipedString(s1 : string , s2 : string ): boolean {
75
+ return s1 .length === s2 .length && (s2 + s2 ).indexOf (s1 ) !== - 1 ;
76
+ }
77
+ ```
78
+
79
+ ### ** Rust**
80
+
81
+ ``` rust
82
+ impl Solution {
83
+ pub fn is_fliped_string (s1 : String , s2 : String ) -> bool {
84
+ s1 . len () == s2 . len () && (s2 . clone () + & s2 ). contains (& s1 )
85
+ }
86
+ }
87
+ ```
88
+
89
+ 原始写法:
90
+
91
+ ``` rust
92
+ impl Solution {
93
+ pub fn is_fliped_string (s1 : String , s2 : String ) -> bool {
94
+ if s1 == s2 {
95
+ return true ;
96
+ }
97
+ if s1 . len () != s2 . len () {
98
+ return false ;
99
+ }
100
+ let s2 : Vec <char > = (s2 . clone () + & s2 ). chars (). collect ();
101
+ let n = s1 . len ();
102
+ let m = s2 . len ();
103
+ for i in 0 .. m - n {
104
+ let mut is_pass = true ;
105
+ for (j , c ) in s1 . chars (). enumerate () {
106
+ if c != s2 [i + j ] {
107
+ is_pass = false ;
108
+ break ;
109
+ }
110
+ }
111
+ if is_pass {
112
+ return true ;
113
+ };
114
+ }
115
+ false
116
+ }
117
+ }
118
+ ```
119
+
71
120
### ** ...**
72
121
73
122
```
Original file line number Diff line number Diff line change @@ -64,6 +64,53 @@ func isFlipedString(s1 string, s2 string) bool {
64
64
}
65
65
```
66
66
67
+ ### ** TypeScript**
68
+
69
+ ``` ts
70
+ function isFlipedString(s1 : string , s2 : string ): boolean {
71
+ return s1 .length === s2 .length && (s2 + s2 ).indexOf (s1 ) !== - 1 ;
72
+ }
73
+ ```
74
+
75
+ ### ** Rust**
76
+
77
+ ``` rust
78
+ impl Solution {
79
+ pub fn is_fliped_string (s1 : String , s2 : String ) -> bool {
80
+ s1 . len () == s2 . len () && (s2 . clone () + & s2 ). contains (& s1 )
81
+ }
82
+ }
83
+ ```
84
+
85
+ ``` rust
86
+ impl Solution {
87
+ pub fn is_fliped_string (s1 : String , s2 : String ) -> bool {
88
+ if s1 == s2 {
89
+ return true ;
90
+ }
91
+ if s1 . len () != s2 . len () {
92
+ return false ;
93
+ }
94
+ let s2 : Vec <char > = (s2 . clone () + & s2 ). chars (). collect ();
95
+ let n = s1 . len ();
96
+ let m = s2 . len ();
97
+ for i in 0 .. m - n {
98
+ let mut is_pass = true ;
99
+ for (j , c ) in s1 . chars (). enumerate () {
100
+ if c != s2 [i + j ] {
101
+ is_pass = false ;
102
+ break ;
103
+ }
104
+ }
105
+ if is_pass {
106
+ return true ;
107
+ };
108
+ }
109
+ false
110
+ }
111
+ }
112
+ ```
113
+
67
114
### ** ...**
68
115
69
116
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn is_fliped_string ( s1 : String , s2 : String ) -> bool {
3
+ s1. len ( ) == s2. len ( ) && ( s2. clone ( ) + & s2) . contains ( & s1)
4
+ }
5
+ }
Original file line number Diff line number Diff line change
1
+ function isFlipedString ( s1 : string , s2 : string ) : boolean {
2
+ return s1 . length === s2 . length && ( s2 + s2 ) . indexOf ( s1 ) !== - 1 ;
3
+ }
You can’t perform that action at this time.
0 commit comments