随笔分类 - LeetCode(数组)
摘要:class Solution { public: vector<int> plusOne(vector<int>& digits) { for(int i = digits.size() - 1; i >= 0 ; i--) { if((++digits[i]) % 10 == 0) { digit
阅读全文
摘要:class Solution { public: int maxSubArray(vector<int>& nums) { int before_addtion = 0; int cur_addtion = 0; int max = INT_MIN; for(int i = 0; i < nums.
阅读全文
摘要://给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。 //你可以假设数组中无重复元素。 class Solution { public: int searchInsert(vector<int>& nums, int targe
阅读全文
摘要:int binarySearch(int[] nums, int target) { int low = 0; int high = nums.length; while (low < high) { int mid = low + ((high - low) >> 1); if (target >
阅读全文
浙公网安备 33010602011771号