Skip to content

Commit 9950cf5

Browse files
committed
feat: add solutions to lcci problem: No.01.09
No.01.09.String Rotation
1 parent afab655 commit 9950cf5

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

lcci/01.09.String Rotation/README.md

+49
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,55 @@ func isFlipedString(s1 string, s2 string) bool {
6868
}
6969
```
7070

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+
71120
### **...**
72121

73122
```

lcci/01.09.String Rotation/README_EN.md

+47
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,53 @@ func isFlipedString(s1 string, s2 string) bool {
6464
}
6565
```
6666

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+
67114
### **...**
68115

69116
```
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function isFlipedString(s1: string, s2: string): boolean {
2+
return s1.length === s2.length && (s2 + s2).indexOf(s1) !== -1;
3+
}

0 commit comments

Comments
 (0)