题目描述:两句话发人深思啊.... Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible. 感觉题目的大致意思就是把数组分成很多个二元数组,对它…
[说明] B2开始到B?(中间不能有空格),定义一维数组Arr_approver() Dim R_sh As Worksheet Set R_sh = ThisWorkbook.Sheets("result") approver_row = R_sh.Range("B2").End(xlDown).Row Arr_approver = R_sh.Range()) For k = LBound(Arr_approver) To UBound(Arr_approver)…
problem 977. Squares of a Sorted Array solution: class Solution { public: vector<int> sortedSquares(vector<int>& A) { for(auto &a:A) a *=a; sort(A.begin(), A.end()); return A; } }; 参考1. Leetcode_easy_977. Squares of a Sorted Array; 完…
problem 852. Peak Index in a Mountain Array solution1: class Solution { public: int peakIndexInMountainArray(vector<int>& A) { return max_element(A.begin(), A.end())-A.begin(); } }; solution2: class Solution { public: int peakIndexInMountainArra…
problem 697. Degree of an Array 题意:首先是原数组的度,其次是和原数组具有相同的度的最短子数组.那么最短子数组就相当于子数组的首末数字都是统计度的数字. solution1: class Solution { public: int findShortestSubArray(vector<int>& nums) { ; unordered_map<int, int> m; unordered_map<int, pair<int,…
problem 532. K-diff Pairs in an Array 题意:统计有重复无序数组中差值为K的数对个数. solution1: 使用映射关系: 统计数组中每个数字的个数.我们可以建立每个数字和其出现次数之间的映射,然后遍历哈希表中的数字,如果k为0且该数字出现的次数大于1,则结果res自增1:如果k不为0,且用当前数字加上k后得到的新数字也在数组中存在,则结果res自增1. class Solution { public: int findPairs(vector<int>&…
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements initi…
Developer deals with arrays every day. Being a collection, an important property to query is the number of items: Array.prototype.length. In JavaScript the length does not always indicate the number of existing elements (for sparse arrays) and modify…
做前端有多年了,看过不少技术文章,学了新的技术,但更新迭代快的大前端,庞大的知识库,很多学过就忘记了,特别在项目紧急的条件下,哪怕心中隐隐约约有学过一个方法,但会下意识的使用旧的方法去解决,多年前ES5几个新增的数组方法,好用但是常忘记用,趁着这周比较清闲,重温下并做下笔记,养成记笔记的好习惯. forEach map filter some every reduce reduceRight forEach forEach是ES5的Array方法中用得最频繁的一个,就是遍历,循环输出,它接受一个…
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more th…
Problem: Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Solution: 复习一下BST的基本性质:简而言之,对于BST中任意结点x,若其有左右结点 l 或 r ,需满足 l.key ≤ x.key ≤ r.key BST的性能(基本操作耗时)与树高成正比,可改进为较为高效的平衡二叉树,即保持整棵树左右均匀,任意左右子树高度差不大于1 如…
Product of Array Except Self Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without division and in O(n). For example, given [1,2…
Merge Sorted Array Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. The number of elements initializ…
题目: Given a sorted (increasing order) array, Convert it to create a binary tree with minimal height. Example Given [1,2,3,4,5,6,7], return 4 / \ 2 6 / \ / \ 1 3 5 7 题解: Solution 1 () class Solution { public: TreeNode *sortedArrayToBST(vector<int> &a…
题目如下: Given an array A of integers, return true if and only if it is a valid mountain array. Recall that A is a mountain array if and only if: A.length >= 3 There exists some i with 0 < i < A.length - 1 such that: A[0] < A[1] < ... A[i-1] &…