array

leetCode Array -- 5.Largest Number At Least Twice of Others

扶醉桌前 提交于 2019-12-05 10:42:49
Problem five: Largest Number At Least Twice of Others In a given integer array nums, there is always exactly one largest element. Find whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, otherwise return -1. Example 1: Input: nums = [3, 6, 1, 0] Output: 1 Explanation: 6 is the largest integer, and for every other number in the array x, 6 is more than twice as big as x. The index of value 6 is 1, so we return 1. Example 2: Input: nums = [1, 2, 3, 4] Output: -1 Explanation: 4 isn’t at least as

算法题——只出现一次的数字

陌路散爱 提交于 2019-12-05 09:15:52
一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字 //num1,num2分别为长度为1的数组。传出参数 //将num1[0],num2[0]设置为返回结果 public class Solution { public static void FindNumsAppearOnce(int [] array,int num1[] , int num2[]) { if(array == null || array.length <= 1){ num1[0] = num2[0] = 0; return; } int len = array.length, index = 0, sum = 0; for(int i = 0; i < len; i++){ sum ^= array[i]; } for(index = 0; index < 32; index++){ if((sum & (1 << index)) != 0) break; } for(int i = 0; i < len; i++){ if((array[i] & (1 << index))!=0){ num2[0] ^= array[i]; }else{ num1[0] ^= array[i]; } } } /** * 数组a中只有一个数出现一次,其他数都出现了2次,找出这个数字 *

Jump Game

岁酱吖の 提交于 2019-12-05 05:17:45
1. Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is to reach the last index in the minimum number of jumps. Example: Input: [2,3,1,1,4] Output: 2 Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index. Note: You can assume that you can always reach the last index. class Solution { public: int jump(vector<int>& nums) { int len = nums.size(),start = 0,end = 0, step = 0;

二级联动下拉框

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 05:08:16
二级联动下拉框 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <select id="privance" onchange="privances()"> </select> <select id="city"> </select> </body> <script> data={"河北省":["石家庄市","唐山市","沧州市","廊坊市","衡水市"], "河南省":["郑州市","洛阳市","新郑市"], "山东省":["德州市","济南市","临沂市","青岛市"]}; var ele=document.getElementById("privance"); var citys=document.getElementById("city"); //默认 var defaults=data["河北省"]; for(var i in defaults) { var option_default=document.createElement("option"); option_default.innerHTML=defaults[i]; citys.appendChild(option_default); } for(var i in

经典排序算法总结

喜欢而已 提交于 2019-12-05 04:26:58
概述 选泡插, 快归堆希桶计基, n方n老(log)n一三, 对n加kn乘k, 不稳稳稳不稳稳, 不稳不稳稳稳稳。 排序算法 平均时间复杂度 最好情况 最坏情况 空间复杂度 排序方式 稳定性 冒泡排序(BubbleSort) O(n 2 ) O(n) O(n 2 ) O(1) In-place 稳定 选择排序(SelectSort) O(n 2 ) O(n 2 ) O(n 2 ) O(1) In-place 不稳 插入排序(InsertSort) O(n 2 ) O(n) O(n 2 ) O(1) In-place 稳定 希尔排序(ShellSort) O(n 1.3 ) O(n) O(n log 2 n) O(1) In-place 不稳 归并排序(MergeSort) O(n log n) O(n log n) O(n log n) O(n) Out-place 稳定 快速排序(QuickSort) O(n log n) O(n log n) O(n 2 ) O(log n) In-place 不稳 堆排序(HeapSort) O(n log n) O(n log n) O(n log n) O(1) In-place 不稳 计数排序(CountSort) O(n + k) O(n + k) O(n + k) O(k) Out-place 稳定 桶排序(BucketSort)

Python scipy.sparse.csr_matrix()[csc_matrix()]

筅森魡賤 提交于 2019-12-05 02:26:33
本文以csr_matrix为例来说明sparse矩阵的使用方法,其他类型的sparse矩阵可以参考 https://docs.scipy.org/doc/scipy/reference/sparse.html csr_matrix是Compressed Sparse Row matrix的缩写组合,下面介绍其两种初始化方法 csr_matrix((data, (row_ind, col_ind)), [shape=(M, N)])   where data , row_ind and col_ind satisfy the relationship a[row_ind[k], col_ind[k]] = data[k] . csr_matrix((data, indices, indptr), [shape=(M, N)])   is the standard CSR representation where the column indices for row i are stored in indices[indptr[i]:indptr[i+1]] and their corresponding values are stored in data[indptr[i]:indptr[i+1]] . If the shape parameter is not supplied,

javascript 简单的数组去重方法

你。 提交于 2019-12-05 02:24:51
一、简单的去重方法,利用数组indexOf方法 // 最简单数组去重法 /* * 新建一新数组,遍历传入数组,值不在新数组就push进该新数组中 * IE8以下不支持数组的indexOf方法 * */ let array = [1, 2, 3, 2, 2, 3, 4, 3, 4, 5]; // 数组去重 function unique(ary) { let newAry = []; for (let i = 0; i<ary.length; i++) { if (newAry.indexOf(ary[i]) === -1) { newAry.push(ary[i]); } } return newAry; } array = unique(ary); console.log(array); 二、ES6中Set方法去重 let ary = [1, 2, 2, 2, 1, 2, 3, 2, 3, 2, 1], console.log(Array.from(new Set(ary))); //=>基于ES6 SET实现去重 或者console.log([...new Set(ary)]); 来源: https://www.cnblogs.com/crystalqiuqiu/p/11897652.html

Using the Render API

爷,独闯天下 提交于 2019-12-05 01:43:55
What Is a Render Array? Many of the variables in template files are straightforward, but you’ll notice that some of the variables are printed along with a function called render(). Render arrays are structured arrays that contain nested data and other information needed by Drupal to turn them into HTML using Drupal’s Render API. Variables that are render arrays are generally easy to spot in template files because they are printed using a function called render(). In page.tpl.php, you’ll notice that all of the regions are printed using the render() function. Each region is an element (another

【leetcode】1243. Array Transformation

依然范特西╮ 提交于 2019-12-05 01:39:22
题目如下: Given an initial array arr , every day you produce a new array using the array of the previous day. On the i -th day, you do the following operations on the array of day i-1 to produce the array of day i : If an element is smaller than both its left neighbor and its right neighbor, then this element is incremented. If an element is bigger than both its left neighbor and its right neighbor, then this element is decremented. The first and last elements never change. After some days, the array does not change. Return that final array. Example 1: Input: arr = [6,2,3,4] Output: [6,3,3,4]

PHP使用数组实现队列、堆栈(实际就是先进先出、先进后出怎样实现)

我只是一个虾纸丫 提交于 2019-12-05 00:22:45
1. array_shift() - 将数组开头的单元移出数组; array_push() - 将一个或多个单元压入数组的末尾(入栈); array_pop() - 弹出数组最后一个单元(出栈) PHP中将一个数组作为一个栈 ,主要是使用array_push()和array_pop()两个系统函数来完毕。(“先进后出”)入栈主要是利用array_push()函数向第一个参数-数组的 尾部 加入一个或多个元素。然后返回新的数组长度。 而PHP中,将数组当做是队列则主要是用array_push和array_shift()实现。(“先进先出”) <?php $zhan=array("WEB");//声明一个数组当做栈/队列 array_push($zhan,"PHP");//将字符串压入栈/队列(数组)中 array_push($zhan,"WWW.CHHUA.COM");//再压入一个元素 array_push($zhan,"WEB开发笔记"); array_push($zhan,"PHP"); array_push($zhan,"站点建设"); print_r($zhan);//打印数组内容 ?> 结果为:Array ( [0] => WEB [1] => PHP [2] => WWW.CHHUA.COM [3] => WEB开发笔记 [4] => PHP [5] => 站点建设 )