mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-12 18:08:38 +08:00
routine
This commit is contained in:
6
25/11/1015.cpp
Normal file
6
25/11/1015.cpp
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
int smallestRepunitDivByK(int k) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
33
25/11/3318.cpp
Normal file
33
25/11/3318.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include <vector>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
std::vector<int> findXSum(std::vector<int> &nums, int k, int x)
|
||||||
|
{
|
||||||
|
int l = 0;
|
||||||
|
int r = k - 1;
|
||||||
|
std::unordered_map<int, int> m;
|
||||||
|
std::vector<int> ans;
|
||||||
|
std::vector<std::pair<int,int>> temp;
|
||||||
|
int count = 0;
|
||||||
|
for(int i = l;i <= k - 1; ++i){
|
||||||
|
m[nums[i]] += 1;
|
||||||
|
}
|
||||||
|
for(int i = 0;r < nums.size();++i){
|
||||||
|
if(i != 0){
|
||||||
|
|
||||||
|
}
|
||||||
|
for (const auto& [key, value] : m) {
|
||||||
|
temp.push_back(std::pair<int,int>(key,value));
|
||||||
|
}
|
||||||
|
std::sort(temp.begin(),temp.end(),[](std::pair<int,int> x,std::pair<int,int> y){
|
||||||
|
return x.second > y.second;
|
||||||
|
});
|
||||||
|
for(int i = 0;i < x;i++){
|
||||||
|
count += temp[i].first * temp[i].second;
|
||||||
|
}
|
||||||
|
ans.push_back(count);
|
||||||
|
temp.clear();
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package D
|
package L12
|
||||||
|
|
||||||
func prefixesDivBy5(nums []int) []bool {
|
func prefixesDivBy5(nums []int) []bool {
|
||||||
ans := make([]bool, len(nums))
|
ans := make([]bool, len(nums))
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package C
|
package L12
|
||||||
|
|
||||||
func kLengthApart(nums []int, k int) bool {
|
func kLengthApart(nums []int, k int) bool {
|
||||||
last := -k - 1
|
last := -k - 1
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package A
|
package L12
|
||||||
|
|
||||||
func minCost(colors string, neededTime []int) int {
|
func minCost(colors string, neededTime []int) int {
|
||||||
count := 0
|
count := 0
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package B
|
package L12
|
||||||
|
|
||||||
func minOperations(nums []int) int {
|
func minOperations(nums []int) int {
|
||||||
n, gcdAll, cnt1 := len(nums), 0, 0
|
n, gcdAll, cnt1 := len(nums), 0, 0
|
||||||
|
|||||||
22
25/11/go/3432.go
Normal file
22
25/11/go/3432.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package L12
|
||||||
|
|
||||||
|
func countPartitions(nums []int) int {
|
||||||
|
n := len(nums)
|
||||||
|
count := 0
|
||||||
|
prefix := make([]int, n)
|
||||||
|
for i, v := range nums {
|
||||||
|
count += v
|
||||||
|
prefix[i] = count
|
||||||
|
}
|
||||||
|
|
||||||
|
ans := 0
|
||||||
|
for i, v := range prefix {
|
||||||
|
if i == n-1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (count-2*v)%2 == 0 {
|
||||||
|
ans++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ans
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user