grep -E '^- \[.*\]\(https://github.com/.*/pull/[0-9]+\)' leetcode.md | wc -l
std::string::substr, std::string::erase,
std::set::emplaceI was thinking about just chilling today, but I ended up doing many household chores and studying hard.
std::move)import heapq
class Solution:
def kSmallestPairs(
self, nums1: list[int], nums2: list[int], k: int
) -> list[list[int]]:
sum_and_pairs: list[tuple[int, tuple[int, int]]] = [
(nums1[0] + nums2[0], (0, 0))
]
checked_pairs: set[tuple[int, int]] = set()
smallest_pairs: list[list[int]] = []
while sum_and_pairs and len(smallest_pairs) < k:
index1, index2 = heapq.heappop(sum_and_pairs)[1]
if (index1, index2) in checked_pairs:
continue
smallest_pairs.append([nums1[index1], nums2[index2]])
checked_pairs.add((index1, index2))
if index1 + 1 < len(nums1):
heapq.heappush(
sum_and_pairs,
(nums1[index1 + 1] + nums2[index2], (index1 + 1, index2)),
)
if index2 + 1 < len(nums2):
heapq.heappush(
sum_and_pairs,
(nums1[index1] + nums2[index2 + 1], (index1, index2 + 1)),
)
return smallest_pairsimport heapq
class Solution:
def kSmallestPairs(
self, nums1: list[int], nums2: list[int], k: int
) -> list[list[int]]:
sum_and_pairs = []
for i in range(len(nums1)):
heapq.heappush(sum_and_pairs, (nums1[i] + nums2[0], (i, 0)))
smallest_pairs = []
while sum_and_pairs and len(smallest_pairs) < k:
index1, index2 = heapq.heappop(sum_and_pairs)[1]
smallest_pairs.append([nums1[index1], nums2[index2]])
if index2 + 1 < len(nums2):
heapq.heappush(
sum_and_pairs,
(nums1[index1] + nums2[index2 + 1], (index1, index2 + 1)),
)
return smallest_pairsrbegin(), rend()std::partial_sum() in numericstd::multiplies is in functionalfor (auto it : num_to_count) { iterating
std::map -> it.first,
it.secondstd::unique_ptr /
std::shared_ptr)dict.keys()std::set
-> std::vector by defining num class constants)list1 -> address of node, *list1 ->
the node itself#include <algorithm>
#include <vector>
class Solution {
public:
int maxProfit(std::vector<int>& prices) {
int profit = 0;
for (int i = 1; i < prices.size(); ++i) {
profit += std::max(0, prices[i] - prices[i - 1]);
}
return profit;
}
};TODO: