Skip to content

Commit

Permalink
feat: add solutions to lc problem: No.0090 (#2115)
Browse files Browse the repository at this point in the history
No.0090.Subsets II
  • Loading branch information
yanglbme authored Dec 17, 2023
1 parent 5d4fd65 commit 7453d33
Show file tree
Hide file tree
Showing 10 changed files with 653 additions and 265 deletions.
43 changes: 21 additions & 22 deletions solution/0000-0099/0038.Count and Say/Solution.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
use std::iter::once;

impl Solution {
pub fn count_and_say(n: i32) -> String {
(1..n)
.fold(vec![1], |curr, _| {
let mut next = vec![];
let mut slow = 0;
for fast in 0..=curr.len() {
if fast == curr.len() || curr[slow] != curr[fast] {
next.extend(once((fast - slow) as u8).chain(once(curr[slow])));
slow = fast;
}
}
next
})
.into_iter()
.map(|digit| (digit + b'0') as char)
.collect()
}
}

use std::iter::once;

impl Solution {
pub fn count_and_say(n: i32) -> String {
(1..n)
.fold(vec![1], |curr, _| {
let mut next = vec![];
let mut slow = 0;
for fast in 0..=curr.len() {
if fast == curr.len() || curr[slow] != curr[fast] {
next.extend(once((fast - slow) as u8).chain(once(curr[slow])));
slow = fast;
}
}
next
})
.into_iter()
.map(|digit| (digit + b'0') as char)
.collect()
}
}
11 changes: 4 additions & 7 deletions solution/0000-0099/0065.Valid Number/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,10 @@ impl Solution {
}
}
if let Some(x) = s.chars().nth(i) {
if x == '.'
&& (i + 1 == n
|| if let Some(m) = s.chars().nth(i + 1) {
m == 'e' || m == 'E'
} else {
false
})
if
x == '.' &&
(i + 1 == n ||
(if let Some(m) = s.chars().nth(i + 1) { m == 'e' || m == 'E' } else { false }))
{
return false;
}
Expand Down
Loading

0 comments on commit 7453d33

Please sign in to comment.