- 博客(7)
- 收藏
- 关注
原创 leet code 二分查找 - 搜索查找位置
//给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。 //// 请必须使用时间复杂度为 O(log n) 的算法。 //// //// 示例 1: //// //输入: nums = [1,3,5,6], target = 5//输出: 2// //// 示例 2: //// //输入: nums = [1,3,5,6], target = 2//输出: 1// //// 示例 3: ////
2021-12-08 21:58:31 152
原创 Leet code 求数组的中心数
//给你一个整数数组 nums ,请计算数组的 中心下标 。 //// 数组 中心下标 是数组的一个下标,其左侧所有元素相加的和等于右侧所有元素相加的和。 //// 如果中心下标位于数组最左端,那么左侧数之和视为 0 ,因为在下标的左侧不存在元素。这一点对于中心下标位于数组最右端同样适用。 //// 如果数组有多个中心下标,应该返回 最靠近左边 的那一个。如果数组不存在中心下标,返回 -1 。 //// //// 示例 1: //// //输入:nums = [1, 7, 3, 6
2021-12-08 21:20:54 116
原创 Leet Code 初练 两数相加
leet code two sum by java//给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。 //// 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 //// 你可以按任意顺序返回答案。 //// //// 示例 1: //// //输入:nums = [2,7,11,15], target = 9//输出:[0,1]//解释:因为 nu
2021-12-08 20:47:02 101
原创 CQU 2020上机
第一题:输入1000以内的数字判断是不是回文数#include<iostream>#include<algorithm>using namespace std;bool iscyclenum(int x) { int a[9] = { 11,22,33,44,55,66,77,88,99 }; if (x < 100) { for (int i = 0; i < 10; i++) { if (a[i] == x) { return tru.
2021-03-17 21:10:50 70
原创 pat 1013 筛法
找素数 pat 乙 1013 #include<iostream>#include<algorithm>using namespace std;#define maxSize 1000001//筛法找素数int findprime(int n, int prime[]) { //n为素数的区间MAX,以及素数数组(记录表) int p[maxSize] = { 0 };//初始化一个1000001大小的数组(查找表) int num = 0;//记录表中数据个数.
2021-03-17 16:46:36 85
原创 2021-03-17
//说反话 pat 乙 1019#include<iostream>#include<string>using namespace std;int main() { char str[90]; char ans[100][100]; cin.getline(str, 90); //gets()函数编译不通过 getline(参数名,大小) int len = strlen(str), row = 0, h = 0; for (int i = 0; i
2021-03-17 16:28:11 50
原创 PAT 甲级 1069 数字黑洞 C++
PAT 甲级 1069 数字黑洞 C++For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from the first
2021-03-15 23:57:04 127
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人