摘要: 1、136、只出现一次的数字 class Solution { public: int singleNumber(vector<int>& nums) { int ret = 0; for (auto e: nums) ret ^= e;/*for(auto x :nums)作用是迭代容器中所有的元 阅读全文
posted @ 2022-10-18 21:15 ZHISHIYIGENICHENG 阅读(28) 评论(0) 推荐(0)
摘要: 1、121买卖股票的最佳时机 class Solution { public: int maxProfit(vector<int>& prices) { int n=(int)prices.size(),ans=0; for(int i=0;i<n;++i){ for(int j=i+1;j<n;+ 阅读全文
posted @ 2022-10-18 13:42 ZHISHIYIGENICHENG 阅读(26) 评论(0) 推荐(0)
摘要: 1、108、将有序数组转换为二叉搜索树(重点) struct TreeNode* helper(int* nums, int left, int right) {//用一个有序数组来建一个名叫helper的二叉树 if (left > right) {//有序数组 return NULL; } // 阅读全文
posted @ 2022-10-17 21:21 ZHISHIYIGENICHENG 阅读(43) 评论(0) 推荐(0)
摘要: 1、27、移除元素 双指针 int removeElement(int* nums, int numsSize, int val) { int left = 0; for (int right = 0; right < numsSize; right++) {//设置两个指针,如果r指针元素不等于v 阅读全文
posted @ 2022-10-17 13:02 ZHISHIYIGENICHENG 阅读(25) 评论(0) 推荐(0)
摘要: 1、26、删除有序数组中的重复项 int removeDuplicates(int* nums, int numsSize) { if (numsSize == 0) { return 0; } int fast = 1, slow = 1;//fast:遍历数组到达的下标位置;slow:下一个不同 阅读全文
posted @ 2022-10-17 10:53 ZHISHIYIGENICHENG 阅读(21) 评论(0) 推荐(0)
摘要: 1、两数之和 方法一:暴力枚举 思路:枚举数组中每一个数,寻找之后的数字是否存在target-x。 int* twoSum(int* nums, int numsSize, int target, int* returnSize) { for (int i = 0; i < numsSize; ++ 阅读全文
posted @ 2022-10-13 23:18 ZHISHIYIGENICHENG 阅读(30) 评论(0) 推荐(0)
摘要: 采用了leetcode官方思路--分治 思路: 求区间内的最大子段和 struct Status { int lSum, rSum, mSum, iSum; };/*结构体用法:struct 结构体名{ 结构体所包含的变量或数组 }; */ //这是一个定义了名叫Status的结构体,里面有四个变量 阅读全文
posted @ 2022-10-13 13:30 ZHISHIYIGENICHENG 阅读(50) 评论(0) 推荐(0)
摘要: 1、C语言标准库函数 qsort(快速排序)声明在stdlib.h文件中,时间复杂度为n*log(n) void qsort( void *base(需要排序的目标数组名), size_t num(参与排序的目标数组元素个数), size_t width(单个元素的大小(或者目标数组中每一个元素长度 阅读全文
posted @ 2022-10-12 21:51 ZHISHIYIGENICHENG 阅读(51) 评论(0) 推荐(0)