//把数组排成最小的数#include "stdafx.h"using namespace std;#include <string>#include <vector>#include <map>#include<algorithm>class Solution{public: string fin ...
分类:
编程语言 时间:
2020-04-19 17:57:25
阅读次数:
72
我的解法是先将2到n的所有素数全部列出来,再计算。将全部的素数列出来用了一个叫“埃拉托色尼筛法”的方法。 算法参照这里:https://www.sohu.com/a/252674565_614593 1 #include <iostream> 2 #include <vector> 3 #inclu ...
分类:
编程语言 时间:
2020-04-19 17:34:37
阅读次数:
71
问题: 给定一个n,有数组1~n, 排列该数组,使得数组两两元素之间的差值有k种。 Example 1: Input: n = 3, k = 1 Output: [1, 2, 3] Explanation: The [1, 2, 3] has three different positive int ...
分类:
其他好文 时间:
2020-04-19 14:58:40
阅读次数:
57
// 二维数组查找#include "stdafx.h"using namespace std;#include <string>#include <vector>class Solution {public: bool Find(int target, vector<vector<int> > a ...
分类:
编程语言 时间:
2020-04-19 14:55:49
阅读次数:
39
题目描述 输入n个整数,找出其中最小的K个数。例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,。 代码: 1.普通人的大顶堆解法 class Solution { public: vector<int> GetLeastNumbers_Solution(vecto ...
分类:
其他好文 时间:
2020-04-19 12:51:54
阅读次数:
53
过了一年来看,这道题还是很妙。 FJOI2016 建筑师 小 Z 是一个很有名的建筑师,有一天他接到了一个很奇怪的任务:在数轴上建 $n$ 个建筑,每个建筑的高度是 $1$ 到 $n$ 之间的一个整数。 小 Z 有很严重的强迫症,他不喜欢有两个建筑的高度相同。另外小 Z 觉得如果从最左边(所有建筑都 ...
分类:
其他好文 时间:
2020-04-19 11:08:48
阅读次数:
60
一:解题思路 二:完整代码示例 (C++版和Java版) C++: class RandomizedSet { private: map<int, int> m_map; vector<int> m_data; public: /** Initialize your data structure h ...
分类:
其他好文 时间:
2020-04-18 22:59:21
阅读次数:
69
#include "stdafx.h"#include <string>using namespace std;#include <vector>#include <stack>typedef struct tag_listnode{ int data; struct tag_listnode *n ...
分类:
其他好文 时间:
2020-04-18 21:19:56
阅读次数:
50
Problem : Given a non empty array of non negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elemen ...
分类:
其他好文 时间:
2020-04-18 18:27:07
阅读次数:
49
1 //BFS + 贪心 2 //维护一个区间[l,r],在这里面可以找到能够跳到最大位置,step++,同时更新l,r 3 class Solution 4 { 5 public: 6 int jump(vector<int>& nums) 7 { 8 if(nums.size() < 2) re ...
分类:
其他好文 时间:
2020-04-18 15:51:53
阅读次数:
45