leetcode324】的更多相关文章

Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3].... Example 1: Input: nums = [1, 5, 1, 1, 6, 4] Output: One possible answer is [1, 4, 1, 5, 1, 6]. Example 2: Input: nums = [1, 3, 2, 2, 3, 1] Output: One po…
class Solution { public void wiggleSort(int[] nums) { int[] temp = Arrays.copyOfRange(nums, 0, nums.length); Arrays.sort(temp); int large = temp.length / 2 + (temp.length % 2 == 0 ? -1 : 0); int small = temp.length - 1; for (int i = 0, j = 1; i < tem…
  1. 首先考虑排序后交替插入 首尾交替插入,这种方法对于有重复数字的数组不可行: class Solution { public: void wiggleSort(vector<int>& nums) { //因为一定存在最优解,所以一定可行的方法就是先排序,然后将最小的数逐渐插入到最大里面: //错误,没有考虑重复答案存在情况: sort(nums.begin(),nums.end()); ; ; vector<int> res; while(i<=j){ if…
C++版 数组和字符串 正文 链表: 正文 树与图: 树: leetcode236. 二叉树的最近公共祖先 递归(先序) leetcode124二叉树最大路径和 递归 图: leetcode 547朋友圈(DFS,并查集) leetcode 207课程表(拓扑排序) leetcode 315 计算右侧小于当前元素的个数 (归并排序.树状数组(BIT),线段树,二叉搜索数(BST)) 回溯算法: leetcode 131分割回文串(回溯.分治.DFS.动态规划) 排序和搜索: leetcode37…