随笔分类 -  LeetCode

摘要:线性表操作练习 双指针练习:移动零 283. 移动零 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。 示例: 输入: [0,1,0,3,12] 输出: [1,3,12,0,0] 说明: 必须在原数组上操作,不能拷贝额外的数组。 尽量减少操作次数。 双层 阅读全文
posted @ 2021-02-15 19:53 sxchen2012 阅读(60) 评论(0) 推荐(0)
摘要:class Solution { public int searchInsert(int[] nums, int target) { int index = 0; if (nums[0] > target) { index = 0; } if (nums[nums.length - 1] < tar 阅读全文
posted @ 2020-06-05 00:04 sxchen2012 阅读(82) 评论(0) 推荐(0)
摘要:class Solution { public int pivotIndex(int[] nums) { int sumLeft = 0; int sum = 0; for (int i = 0; i < nums.length; i++) { sum += nums[i]; } for (int 阅读全文
posted @ 2020-06-04 23:47 sxchen2012 阅读(91) 评论(0) 推荐(0)