![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
笔试编程
西子云齐
自律即自由
展开
-
贿赂糖果,使得第一名候选人支持人最多
#include <iostream> #include <vector> #include <algorithm> using namespace std; /* n(投票人数),m(候选人数) a(候选人m),b(被贿赂需要糖果数) */ bool vector_greater(const vector<long> & v...原创 2018-09-11 11:15:29 · 160 阅读 · 0 评论 -
找出数据中超过一半的数字
class Solution { public: int MoreThanHalfNum_Solution(vector<int> numbers) { int n = numbers.size(); if (n == 0) return 0; /* 就好比,假如秦国强于六国和,那么秦国更能血拼过(齐国战赵国+...转载 2018-09-11 11:18:29 · 158 阅读 · 0 评论 -
二分法
#include <iostream> using namespace std; int search(int *b, int n, int q) { int s = 1, e = n; while(s<=e&&e<=n&&s>=1) { int m = (s + e) / 2; if...原创 2018-09-11 11:20:36 · 193 阅读 · 0 评论 -
实现得到自定义栈最小值的函数
定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1))。 class Solution { public: stack<int> stack1,stack2; void push(int value) { stack1.push(value); if(stack2.empty()) ...转载 2018-09-11 11:24:03 · 168 阅读 · 0 评论 -
孤岛问题
#include<vector> #include<iostream> using namespace std; class Solution { public: void setOne(vector<vector<char>> &grid, int row, int col) { int m = grid.size(...转载 2018-09-11 10:38:54 · 1545 阅读 · 0 评论 -
最大不重复子串的长度及其索引
#include &quot;stdafx.h&quot; #include&amp;lt;iostream&amp;gt; #include&amp;lt;string&amp;gt; using namespace std; int max(int num1, int num2) { return num1 &amp;gt;= num2 ? num1 : num2; } int转载 2018-09-11 10:36:51 · 233 阅读 · 0 评论 -
堆排序
#include <iostream> #include<algorithm> using namespace std; //时间复杂度为O(nlogk) void HeapAdjust(int *a,int i,int size) //调整堆 {//调整数组a[1]为根节点、a[size]为节点且a[i]节点开始的二叉树为堆排序。 int lchi...转载 2018-09-11 10:46:42 · 83 阅读 · 0 评论 -
链表反转
// alithan.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> #include<vector> using namespace std; template <class T> int getAr...转载 2018-09-11 10:56:18 · 114 阅读 · 0 评论 -
数字按范围显示
#include "stdafx.h" #include&lt;iostream&gt; #include &lt;algorithm&gt; #include&lt;string&gt; #include&lt;vector&gt; using namespace std; void main() { int a; vect原创 2018-09-11 11:03:24 · 196 阅读 · 0 评论