- 博客(4)
- 收藏
- 关注
原创 C++ STL 动态数组(vector)
##了解vector #include<bits/stdc++.h> using namespace std; int main() { vector<char>v{'a','b','c','d','e'}; cout<<v[3]<<endl; v.push_back('f'); //在v后面添加一个元素'f' cout<<v.size()<<endl;//此时长度为6 v.resize(7);//把v长度设定为 7个
2022-01-17 11:45:10
203
原创 C++ STL字符串学习
今天主要学习了C++ STL中的字符串,通过编程了解函数功能,并做了一些练习。 ##函数学习 #include<bits/stdc++.h> using namespace std; int main() { string s="hello"; string n="world"; cout<<(s+=n)<<'\n';/*连接运算符*/ cout<<s.substr(1,4)<<'\n';//substr(p,n):返回从s的下标p
2022-01-16 19:26:56
383
原创 有序数组的平方
##题目: 给你一个按 非递减顺序 排序的整数数组 nums,返回 每个数字的平方 组成的新数组,要求也按 非递减顺序 排序。 ##代码: int* sortedSquares(int* nums, int numsSize, int* returnSize){ int* ans=malloc(sizeof(int)*numsSize); *returnSize = numsSize; for(int i=0,j=numsSize-1,pos=numsSize-1;i<
2022-01-15 18:53:15
358
原创 二分法查找
##题目: 给定一个n个元素有序的(升序)整型数组nums 和一个目标值target ,写一个函数搜索nums中的 target,如果目标值存在返回下标,否则返回 -1。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/binary-search 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 ##代码: intsearch(int*nums,intnumsSize,inttarget){ ...
2022-01-14 11:02:38
94
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人