Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7ba0acb

Browse files
committed
feat: add solutions to lc problem: No.1455
No.1455.Check If a Word Occurs As a Prefix of Any Word in a Sentence
1 parent ec5850f commit 7ba0acb

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

‎solution/1400-1499/1455.Check If a Word Occurs As a Prefix of Any Word in a Sentence/README.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,37 @@ func isPrefixOfWord(sentence string, searchWord string) int {
124124
}
125125
```
126126

127+
### **TypeScript**
128+
129+
```ts
130+
function isPrefixOfWord(sentence: string, searchWord: string): number {
131+
const ss = sentence.split(/\s/);
132+
const n = ss.length;
133+
for (let i = 0; i < n; i++) {
134+
if (ss[i].startsWith(searchWord)) {
135+
return i + 1;
136+
}
137+
}
138+
return -1;
139+
}
140+
```
141+
142+
### **Rust**
143+
144+
```rust
145+
impl Solution {
146+
pub fn is_prefix_of_word(sentence: String, search_word: String) -> i32 {
147+
let ss = sentence.split_whitespace().collect::<Vec<&str>>();
148+
for i in 0..ss.len() {
149+
if ss[i].starts_with(&search_word) {
150+
return (i + 1) as i32;
151+
}
152+
}
153+
-1
154+
}
155+
}
156+
```
157+
127158
### **...**
128159

129160
```

‎solution/1400-1499/1455.Check If a Word Occurs As a Prefix of Any Word in a Sentence/README_EN.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,37 @@ func isPrefixOfWord(sentence string, searchWord string) int {
107107
}
108108
```
109109

110+
### **TypeScript**
111+
112+
```ts
113+
function isPrefixOfWord(sentence: string, searchWord: string): number {
114+
const ss = sentence.split(/\s/);
115+
const n = ss.length;
116+
for (let i = 0; i < n; i++) {
117+
if (ss[i].startsWith(searchWord)) {
118+
return i + 1;
119+
}
120+
}
121+
return -1;
122+
}
123+
```
124+
125+
### **Rust**
126+
127+
```rust
128+
impl Solution {
129+
pub fn is_prefix_of_word(sentence: String, search_word: String) -> i32 {
130+
let ss = sentence.split_whitespace().collect::<Vec<&str>>();
131+
for i in 0..ss.len() {
132+
if ss[i].starts_with(&search_word) {
133+
return (i + 1) as i32;
134+
}
135+
}
136+
-1
137+
}
138+
}
139+
```
140+
110141
### **...**
111142

112143
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
impl Solution {
2+
pub fn is_prefix_of_word(sentence: String, search_word: String) -> i32 {
3+
let ss = sentence.split_whitespace().collect::<Vec<&str>>();
4+
for i in 0..ss.len() {
5+
if ss[i].starts_with(&search_word) {
6+
return (i + 1) as i32;
7+
}
8+
}
9+
-1
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function isPrefixOfWord(sentence: string, searchWord: string): number {
2+
const ss = sentence.split(/\s/);
3+
const n = ss.length;
4+
for (let i = 0; i < n; i++) {
5+
if (ss[i].startsWith(searchWord)) {
6+
return i + 1;
7+
}
8+
}
9+
return -1;
10+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /