博客中的练习题解答

题目需要思考了才有价值, 所以在我的博客中给出的练习题都不直接给答案, 在这里进行集中解答. 有需要者自取.

Py1

1
2
3
4
5
6
7
8
A = np.array([
[1, 1, 1, 5, 5, 5],
[1, 1, 1, 5, 5, 5],
[4, 4, 4, 6, 6, 6],
[4, 4, 4, 6, 6, 6]
])
B = np.lib.stride_tricks.as_strided(A, shape=(2,2,2,3), strides=(48,12,24,4))
print(B)

包含min函数的栈

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.Stack;

public class Solution {

Stack<Integer> dataStack = new Stack<>();
Stack<Integer> minStack = new Stack<>();

public void push(int node) {
dataStack.push(node);
if(minStack.isEmpty() || node <= minStack.peek()) {
minStack.push(node);
}
}

public void pop() {
int out = dataStack.pop();
if(out == minStack.peek()) {
minStack.pop();
}
}

public int top() {
return dataStack.peek();
}

public int min() {
return minStack.peek();
}
}

所有奇数长度子数组的和


Leetcode 1588

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public:
int sumOddLengthSubarrays(vector<int>& arr) {
int len = arr.size();
vector<int> preSum(len+1);
for(int i=1; i<=len; ++i) {
preSum[i] = preSum[i-1] + arr[i-1];
}
int sum = 0;
for(int k=1; k<=len; k+=2) {
for(int j=k; j<=len; ++j) {
sum += preSum[j]-preSum[j-k];
}
}
return sum;
}
};

Accumulation of English writing by examples

  1. C

汇编语言学习笔记

  1. 64KB

MySQL与大表优化

1、2NF;2、3NF;4、BCNF

Python 基础 | 系列数据结构的拆封 Python 科学运算 | 形状与跨度元组

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×