Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
LNKLEO committed Apr 10, 2022
1 parent db352f0 commit 250046b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 9 deletions.
5 changes: 5 additions & 0 deletions C#/1611.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Solution {
public int MinimumOneBitOperations(int n) {
return n < 2 ? n : (int)Math.Pow(2, (int)Math.Log(n, 2)) + MinimumOneBitOperations((3 << ((int)Math.Log(n, 2) - 1)) ^ n);
}
}
39 changes: 39 additions & 0 deletions GO/1712.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
func waysToSplit(nums []int) int {
count := 0
partial := make([]int, len(nums))
partial[0] = nums[0]
for i := 1; i < len(nums); i++ {
partial[i] = partial[i-1] + nums[i]
}
sum := partial[len(partial)-1]
sr := 2 * sum / 3
ir := len(nums) - 1
for sr < partial[ir-1] {
ir--
}
ilc := ir - 1
ilf := ilc - 1
for ir > 1 {
sc := partial[ir-1] / 2
sf := 2*partial[ir-1] - sum
if ir-1 < ilc {
ilc = ir - 1
}
for ilc > 0 && sc < partial[ilc-1] {
ilc--
}
if ilc < ilf && ilc > 0 {
ilf = ilc
}
for ilf > 0 && sf <= partial[ilf-1] {
ilf--
}
if ilc < 1 {
break
}
count += ilc - ilf
count %= 1000000007
ir--
}
return count
}
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
## Summary
|Language| Easy |Medium| Hard | All |
|:------:|:----:|:----:|:----:|:----:|
| C# | 0 | 1 | 0 | 1 |
| RUST | 0 | 1 | 0 | 1 |
| GO | 0 | 1 | 0 | 1 |
| | 0 | 3 | 0 | 3 |
| C# | 0 | 1 | 1 | 2 |
| RUST | 0 | 1 | 1 | 2 |
| GO | 0 | 2 | 0 | 2 |
| | 0 | 4 | 2 | 6 |

## Detail
| ID|Name |Difficulty| C# |RUST| GO |
|---:|:-------------------------------------------|:--------:|:--:|:--:|:--:|
|1054|Distant Barcodes | Medium | AC | | |
|1901|Find a Peak Element II | Medium | | | AC |
|2146|K Highest Ranked Items Within a Price Range | Medium | | AC | |
| ID|Name |Difficulty| C# |RUST| GO |
|---:|:-----------------------------------------------|:--------:|:--:|:--:|:--:|
|1054|Distant Barcodes | Medium | AC | | |
|1402|Reducing Dishes | HARD | | AC | |
|1611|Minimum One Bit Operations to Make Integers Zero| HARD | AC | | |
|1712|Ways to Split Array Into Three Subarrays | Medium | | | AC |
|1901|Find a Peak Element II | Medium | | | AC |
|2146|K Highest Ranked Items Within a Price Range | Medium | | AC | |
16 changes: 16 additions & 0 deletions RUST/1402.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
impl Solution {
pub fn max_satisfaction(satisfaction: Vec<i32>) -> i32 {
let mut dishes = satisfaction.clone();
dishes.sort_by(|a,b| b.cmp(a));
let mut answer = 0;
let mut partial = 0;
for dish in dishes {
partial += dish;
if partial < 0 {
return answer;
}
answer += partial;
}
return answer;
}
}

0 comments on commit 250046b

Please sign in to comment.