冒泡排序 /*原理是相邻的数两两交换,按照从小到大或者从大到小的顺序进行交换, 这样一趟过去后,最大或最小的数字被交换到了最后一位, 然后再从头开始进行两两比较交换,直到倒数第二位时结束;*/ //由于冒泡排序算法本身就是一种低效算法,即使判断了在某种条件下已经排序好直接退出,也是十分的耗时 简单选 Read More
posted @ 2017-12-28 21:58 A-inspire Views(342) Comments(0) Diggs(1) Edit
珂珂喜欢吃香蕉。这里有 n 堆香蕉,第 i 堆中有 piles[i] 根香蕉。警卫已经离开了,将在 h 小时后回来。 珂珂可以决定她吃香蕉的速度 k (单位:根/小时)。每个小时,她将会选择一堆香蕉,从中吃掉 k 根。如果这堆香蕉少于 k 根,她将吃掉这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉 Read More
posted @ 2022-09-09 23:01 A-inspire Views(20) Comments(0) Diggs(0) Edit
给你两个整数数组 arr1 , arr2 和一个整数 d ,请你返回两个数组之间的 距离值 。 「距离值」 定义为符合此距离要求的元素数目:对于元素 arr1[i] ,不存在任何元素 arr2[j] 满足 |arr1[i]-arr2[j]| <= d 。 示例 1: 输入:arr1 = [4,5,8 Read More
posted @ 2022-09-07 11:59 A-inspire Views(24) Comments(0) Diggs(0) Edit
给定一个长度为 n 的整数数组 height 。有 n 条垂线,第 i 条线的两个端点是 (i, 0) 和 (i, height[i]) 。 找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。 返回容器可以储存的最大水量。 说明:你不能倾斜容器。 提示: n == height.l Read More
posted @ 2022-06-22 12:07 A-inspire Views(29) Comments(0) Diggs(0) Edit
给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。 代码: class Solution { public: int lengthOfLongestSubstring(string s) { int start = 0; int maxCnt = 0; for(int i = 0 Read More
posted @ 2022-06-22 11:11 A-inspire Views(11) Comments(0) Diggs(0) Edit
思路: 算法可以按以下步骤进行: 先把这一群人按某种顺序排列 依据上述的顺序,加入到一个新的集合达成重新排列 1 中所说的某种顺序,根据题目要求应该为身高降序,也就是说先考虑把身高较高的人放入新集合,这样在高个子前面或后面插入矮个子都不会影响当前高个子的k值;其次,k值应该升序排列,k值较大的较后插 Read More
posted @ 2022-04-08 09:14 A-inspire Views(44) Comments(0) Diggs(0) Edit
思路:选取一个方向数组,判定当前的方向,对应的坐标相加 #include <iostream> #include <string> #include <algorithm> using namespace std; // 定义北东南西四个方向 int g_to[4][2] = {{0, 1}, {1 Read More
posted @ 2022-03-08 19:37 A-inspire Views(74) Comments(0) Diggs(0) Edit
思路:c++ 中心扩散,一前一后寻找相同的字符串,当找到后从两边进行扩展。 代码: #include <iostream> #include <string> using namespace std; const int MAX_LETTER = 26; int main() { int res = Read More
posted @ 2022-03-01 19:46 A-inspire Views(53) Comments(0) Diggs(0) Edit
1、题目描述 代码: #include <iostream> #include <string> using namespace std; const int MAX_LETTER = 26; int main() { string source; string target; cin>>sourc Read More
posted @ 2022-03-01 19:25 A-inspire Views(124) Comments(0) Diggs(0) Edit
代码: #include <iostream> #include <string> #include <algorithm> #include <vector> #include <map> using namespace std; int Comp(string a, string b) { re Read More
posted @ 2022-02-24 09:34 A-inspire Views(34) Comments(0) Diggs(0) Edit
思路:排序+二分 代码: #include <iostream> #include <vector> #include <algorithm> using namespace std; bool BinSerch(const vector<int>& arr, int start, int targ Read More
posted @ 2022-02-18 21:55 A-inspire Views(302) Comments(0) Diggs(0) Edit