c# 算法及数据结构每日练习记录_3
1.
https://leetcode.cn/problems/move-zeroes/description/?envType=study-plan&id=suan-fa-ru-men&plan=algorithms&plan_progress=b48xitv&orderBy=most_votes&languageTags=csharp
给定一个数组 nums
,编写一个函数将所有 0
移动到数组的末尾,同时保持非零元素的相对顺序。
请注意
2.
https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/?envType=study-plan&id=suan-fa-ru-men&plan=algorithms&plan_progress=b48xitv
给你一个下标从 1 开始的整数数组 numbers
,该数组已按 非递减顺序排列 ,请你从数组中找出满足相加之和等于目标数 target
的两个数。如果设这两个数分别是 numbers[index1]
和 numbers[index2]
,则 1 <= index1 < index2 <= numbers.length
。
以长度为 2 的整数数组 [index1, index2]
的形式返回这两个整数的下标 index1
和 index2
。
你可以假设每个输入 只对应唯一的答案 ,而且你 不可以 重复使用相同的元素。
你所设计的解决方案必须只使用常量级的额外空间
1.
https://leetcode.cn/problems/intersection-of-two-arrays-ii/solutions/?orderBy=most_votes&languageTags=csharp
nums1
和 nums2
2.
https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/?envType=study-plan&id=shu-ju-jie-gou-ru-men&plan=data-structures&plan_progress=b4tf6qe
给定一个数组 prices
,它的第 个元素 prices[i]
表示一支给定股票第 i
天的价格。
你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。
返回你可以从这笔交易中获取的最大利润。如果你不能获取任何利润,返回 0