-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
feat: add solutions for lc No.2574 #5120
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| impl Solution { | ||
| pub fn find_the_string(lcp: Vec<Vec<i32>>) -> String { | ||
| let n = lcp.len(); | ||
| let mut s = vec!['\0'; n]; | ||
| let mut i = 0; | ||
|
|
||
| for c in b'a'..=b'z' { | ||
| while i < n && s[i] != '\0' { | ||
| i += 1; | ||
| } | ||
| if i == n { | ||
| break; | ||
| } | ||
| for j in i..n { | ||
| if lcp[i][j] > 0 { | ||
| s[j] = c as char; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for i in 0..n { | ||
| if s[i] == '\0' { | ||
| return "".to_string(); | ||
| } | ||
| } | ||
|
|
||
| for i in (0..n).rev() { | ||
| for j in (0..n).rev() { | ||
| if s[i] == s[j] { | ||
| if i == n - 1 || j == n - 1 { | ||
| if lcp[i][j] != 1 { | ||
| return "".to_string(); | ||
| } | ||
| } else if lcp[i][j] != lcp[i + 1][j + 1] + 1 { | ||
| return "".to_string(); | ||
| } | ||
| } else if lcp[i][j] > 0 { | ||
| return "".to_string(); | ||
| } | ||
| } | ||
|
Comment on lines
+27
to
+40
|
||
| } | ||
|
|
||
| s.into_iter().collect() | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR title references adding solutions for LC 2574, but this PR also adds a new Rust solution for LC 2573 and updates its documentation. Please update the PR title (or description) to reflect LC 2573 additions and the LC 2574 consolidation/renaming so the change scope is accurately represented.