mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-02-27 11:58:39 +08:00
routine
This commit is contained in:
15
26/01/1895.cpp
Normal file
15
26/01/1895.cpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
int largestMagicSquare(std::vector<std::vector<int>>& grid) {
|
||||||
|
int m = grid.size();
|
||||||
|
int n = grid[0].size();
|
||||||
|
std::vector<std::vector<int>> preM(m,std::vector<int>(n,0)),preN(m,std::vector<int>(n,0));
|
||||||
|
for (int i = 0; i < m; i++) {
|
||||||
|
for(int j = 0;j < n;j++){
|
||||||
|
preM[m][n] += grid[m][n];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
33
26/01/3507.cpp
Normal file
33
26/01/3507.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include <climits>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
bool isIncrease(std::vector<int>& nums){
|
||||||
|
for (int i = 1; i<nums.size(); ++i) {
|
||||||
|
if (nums[i] < nums[i-1]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int minimumPairRemoval(std::vector<int>& nums) {
|
||||||
|
int ans = 0;
|
||||||
|
while (!isIncrease(nums)) {
|
||||||
|
int index = 0;
|
||||||
|
int minX = INT_MAX;
|
||||||
|
for (int i = 0; i< nums.size()-1; i++) {
|
||||||
|
int temp = nums[i]+nums[i+1];
|
||||||
|
if (minX > temp) {
|
||||||
|
minX = temp;
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nums.erase(nums.begin()+index+1);
|
||||||
|
nums[index] = minX;
|
||||||
|
ans++;
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
};
|
||||||
23
26/01/comp/18q1.cpp
Normal file
23
26/01/comp/18q1.cpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
int vowelConsonantScore(std::string s) {
|
||||||
|
int v =0,c=0;
|
||||||
|
std::string col = "aeiou";
|
||||||
|
for (auto i : s) {
|
||||||
|
if (i > 122 || i < 97) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (col.find(i) != std::string::npos) {
|
||||||
|
v++;
|
||||||
|
}else {
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (c==0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return v/c;
|
||||||
|
}
|
||||||
|
};
|
||||||
38
26/01/go/3507.go
Normal file
38
26/01/go/3507.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package A
|
||||||
|
|
||||||
|
import "math"
|
||||||
|
|
||||||
|
func isIncrease(nums []int) bool {
|
||||||
|
for i := range nums {
|
||||||
|
if i == len(nums)-1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if nums[i] > nums[i+1] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func minimumPairRemoval(nums []int) int {
|
||||||
|
ans := 0
|
||||||
|
index := 0
|
||||||
|
temp := 0
|
||||||
|
for !isIncrease(nums) {
|
||||||
|
minX := math.MaxInt
|
||||||
|
for i := range nums {
|
||||||
|
if i == len(nums)-1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
temp = nums[i] + nums[i+1]
|
||||||
|
if minX > temp {
|
||||||
|
minX = temp
|
||||||
|
index = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nums[index] = minX
|
||||||
|
nums = append(nums[:index+1], nums[index+2:]...)
|
||||||
|
ans++
|
||||||
|
}
|
||||||
|
return ans
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user