File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed
2300-2399/2348.number-of-zero-filled-subarrays Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn judge_point24 ( cards : Vec < i32 > ) -> bool {
3
+ fn dfs ( nums : Vec < f64 > ) -> bool {
4
+ let n = nums. len ( ) ;
5
+ if n == 1 {
6
+ return ( nums[ 0 ] - 24.0 ) . abs ( ) < 1e-6 ;
7
+ }
8
+ for i in 0 ..n {
9
+ for j in 0 ..n {
10
+ if i == j {
11
+ continue ;
12
+ }
13
+ let mut nxt = Vec :: new ( ) ;
14
+ for k in 0 ..n {
15
+ if k != i && k != j {
16
+ nxt. push ( nums[ k] ) ;
17
+ }
18
+ }
19
+ for op in 0 ..4 {
20
+ let mut nxt2 = nxt. clone ( ) ;
21
+ match op {
22
+ 0 => {
23
+ nxt2. push ( nums[ i] + nums[ j] ) ;
24
+ }
25
+ 1 => {
26
+ nxt2. push ( nums[ i] - nums[ j] ) ;
27
+ }
28
+ 2 => {
29
+ nxt2. push ( nums[ i] * nums[ j] ) ;
30
+ }
31
+ 3 => {
32
+ if nums[ j] . abs ( ) < 1e-6 {
33
+ continue ;
34
+ }
35
+ nxt2. push ( nums[ i] / nums[ j] ) ;
36
+ }
37
+ _ => { }
38
+ }
39
+ if dfs ( nxt2) {
40
+ return true ;
41
+ }
42
+ }
43
+ }
44
+ }
45
+ false
46
+ }
47
+
48
+ let nums: Vec < f64 > = cards. into_iter ( ) . map ( |x| x as f64 ) . collect ( ) ;
49
+ dfs ( nums)
50
+ }
51
+ }
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn zero_filled_subarray ( nums : Vec < i32 > ) -> i64 {
3
+ let mut ans: i64 = 0 ;
4
+ let mut cnt: i64 = 0 ;
5
+ for x in nums {
6
+ if x == 0 {
7
+ cnt += 1 ;
8
+ ans += cnt;
9
+ } else {
10
+ cnt = 0 ;
11
+ }
12
+ }
13
+ ans
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments