- 博客(10)
- 收藏
- 关注
原创 坚持刷题300题——盛最多水的容器(3)
坚持刷题300题——盛最多水的容器(3) 给你 n 个非负整数 a1,a2,…,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0) 。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。 说明:你不能倾斜容器。 示例 1: 输入:[1,8,6,2,5,4,8,3,7] 输出:49 解释:图中垂直线代表输入数组 [1,8,6,2,5,4,8,3,7]。在此情况下,容器能够容纳水(表示为蓝色部分)的最大值为
2021-08-09 03:23:19
304
原创 坚持刷题300题——Z 字形变换(2)
坚持刷题300题——Z 字形变换(2) 将一个给定字符串 s 根据给定的行数 numRows ,以从上往下、从左到右进行 Z 字形排列。 比如输入字符串为 “PAYPALISHIRING” 行数为 3 时,排列如下: P A H N A P L S I I G Y I R 之后,你的输出需要从左往右逐行读取,产生出一个新的字符串,比如:“PAHNAPLSIIGYIR”。 请你实现这个将字符串进行指定行数变换的函数: string convert(string s, int numRows
2021-08-09 02:27:35
121
原创 坚持刷题300题——最长回文子串(1)
最长回文子串 给你一个字符串 s,找到 s 中最长的回文子串。 示例 1: 输入:s = “babad” 输出:“bab” 解释:“aba” 同样是符合题意的答案。 示例 2: 输入:s = “cbbd” 输出:“bb” 示例 3: 输入:s = “a” 输出:“a” 示例 4: 输入:s = “ac” 输出:“a” #include <iostream> #include<string> using namespace std; void handle(string s) {
2021-08-08 00:34:44
87
原创 九种排序算法——归并排序(稳定)
九种排序算法——归并排序(稳定) #include<iostream> #include <cstring> using namespace std; void handle(int A[],int low,int mid,int high){ int *B=new int[12]; int i,j,k; for(k=low;k<=high;k++){ B[k]=A[k]; } for(i=low,j=mid+1,k=i
2021-07-29 04:34:25
133
原创 九种排序算法——直接选择排序(不稳定)
九种排序算法——直接选择排序(不稳定) #include<iostream> #include <cstring> using namespace std; void handle(int A[],int n){ for(int i=0;i<n-1;i++){ int min =i; for(int j=i+1;j<n;j++) { if(A[j]<A[min]){
2021-07-29 04:01:01
309
原创 九种常用排序——快速排序(不稳定)
九种常用排序——快速排序(不稳定) #include<iostream> #include <cstring> using namespace std; void display(int A[],int n){ for(int i=0;i<n;i++) { cout<<A[i]<<" "; } cout<<endl; } int handle(int A[],int low,int high
2021-07-29 03:50:20
186
原创 九种排序算法——冒泡排序(稳定)
九种排序算法——冒泡排序(稳定) #include<iostream> #include <cstring> using namespace std; void ShellSort(int A[],int n) { int i,j; for(i=0;i<n;i++) { for (j=0;j<n-i-1;j++) { if(A[j]>A[j+1]) {
2021-07-29 01:37:04
278
原创 九种常用排序——希尔排序(不稳定)
九种常用排序——希尔排序(不稳定) #include<iostream> #include <cstring> using namespace std; void ShellSort(int A[],int n) { int i,j; for(int dk=n/2;dk >= 1;dk /= 2) { for(i=dk+1;i<=n;++i) { if(A[i]<A[i-dk]){
2021-07-29 01:28:14
209
原创 九种排序——折半插入排序(稳定)
九种排序——折半插入排序(稳定) #include<iostream> #include <cstring> using namespace std; void BInterSort(int A[],int n) { int i,j; int low,high,mid; for(i=2 ;i<= n;i++){ A[0]=A[i]; low=1;high=i-1; while(low<=high)
2021-07-27 01:17:49
146
原创 九种常用排序——直接插入排序
九种常用排序——直接插入排序(稳定) #include<iostream> #include <cstring> using namespace std; void InterSort(int A[],int n) { int i,j; for(i=2;i<=n;i++){ A[0]=A[i]; //取数组第一位为标志位 for(j=i-1;A[0]<A[j];j--){ A[j+1]=A[j];
2021-07-27 01:02:56
87
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人