Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add solutions to lc problems: No.3029 #2316

Merged
merged 9 commits into from
Feb 4, 2024
Prev Previous commit
Next Next commit
feat: add solutions to lc problems: No.3029
  • Loading branch information
Nothing-avil authored Feb 4, 2024
commit 9dcbbfd3f57beae67d0ec9178adbe20349256641
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,118 @@ It can be shown that 4 seconds is the minimum time greater than zero required fo
<!-- tabs:start -->

```python
class Solution:
def minimumTimeToInitialState(self, word: str, k: int) -> int:
n = len(word)
for i in range(1, 10001):
re = i * k
if re >= n:
return i
if word[re:] == word[:n - re]:
return i
return 0

```

```java

class Solution {
public int minimumTimeToInitialState(String word, int k) {
int n = word.length();
for (int i = 1; i <= 10000; i++) {
int re = i * k;
if (re >= n) {
return i;
}
String str = word.substring(re);
boolean flag = true;
for (int j = 0; j < str.length(); j++) {
if (str.charAt(j) != word.charAt(j)) {
flag = false;
break;
}
}
if (flag) {
return i;
}
}
return 0;
}
}
```

```cpp

class Solution {
public:
int minimumTimeToInitialState(string word, int k) {
int n = word.length();
for (int i = 1; i <= 10000; i++) {
int re = i * k;
if (re >= n) {
return i;
}
string str = word.substr(re);
bool flag = true;
for (int j = 0; j < str.length(); j++) {
if (str[j] != word[j]) {
flag = false;
break;
}
}
if (flag) {
return i;
}
}
return 0;
}
};
```

```go
func minimumTimeToInitialState(word string, k int) int {
n := len(word)
for i := 1; i <= 10000; i++ {
re := i * k
if re >= n {
return i
}
str := word[re:]
flag := true
for j := 0; j < len(str); j++ {
if str[j] != word[j] {
flag = false
break
}
}
if flag {
return i
}
}
return 0
}
```

```ts
function minimumTimeToInitialState(word: string, k: number): number {
const n = word.length;
for (let i = 1; i <= 10000; i++) {
const re = i * k;
if (re >= n) {
return i;
}
const str = word.substring(re);
let flag = true;
for (let j = 0; j < str.length; j++) {
if (str[j] !== word[j]) {
flag = false;
break;
}
}
if (flag) {
return i;
}
}
return 0;
}
```

<!-- tabs:end -->
Expand Down