array

lintcode-medium-Nuts & Bolts Problem

可紊 提交于 2020-02-17 11:28:25
Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping between nuts and bolts. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to see which one is bigger/smaller. We will give you a compare function to compare nut with bolt. Example Given nuts = ['ab','bc','dd','gg'] , bolts = ['AB','GG', 'DD', 'BC'] . Your code should find the matching bolts and nuts. one of the possible return: nuts = ['ab','bc','dd','gg'] , bolts = ['AB','BC','DD','GG']

numpy 数组得创建

[亡魂溺海] 提交于 2020-02-17 10:23:36
import numpy as num # 1. shuzu1 = num.array([1, 2, 3]) print(shuzu1) print(type(shuzu1)) # [1 2 3] # <class 'numpy.ndarray'> # 2. shuzu2 = num.array(range(10)) print(shuzu2) # [0 1 2 3 4 5 6 7 8 9] # 3. shuzu3 = num.arange(10) print(shuzu3) print(type(shuzu3)) # [0 1 2 3 4 5 6 7 8 9] # <class 'numpy.ndarray'> print(shuzu3.dtype) # int32 # numpy中的数据类型 shuzu4 = num.array(range(1, 4), dtype=float) print(shuzu4) print(shuzu4.dtype) # [1. 2. 3.] # float64 # numpy中的bool类型 shuzu5 = num.array([1, 0, 1, 1, 1, 0, 0, 1], dtype=bool) print(shuzu5) print(shuzu5.dtype) # [ True False True True True False

ZOJ 3872: Beauty of Array(思维)

不想你离开。 提交于 2020-02-17 07:24:26
Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous subarray of the array A. Input There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case: The first line contains an integer N (1 <= N <= 100000), which indicates the size of the array. The next line contains N positive integers separated by spaces. Every integer

c#字符串及数组操作

 ̄綄美尐妖づ 提交于 2020-02-17 04:30:41
字符串操作(取当前时间) string time=convert.tostring(DateTime.Today).split( new char []{' '}); textbox1.text=time[0]; 以空格作为分界点; 数组概述 C# 数组从零开始建立索引,即数组索引从零开始。C# 中数组的工作方式与在大多数其他流行语言中的工作方式类似。但还有一些差异应引起注意。 声明数组时,方括号 ([]) 必须跟在类型后面,而不是标识符后面。在 C# 中,将方括号放在标识符后是不合法的语法。 int[] table; // not int table[]; 另一细节是,数组的大小不是其类型的一部分,而在 C 语言中它却是数组类型的一部分。这使您可以声明一个数组并向它分配 int 对象的任意数组,而不管数组长度如何。 int[] numbers; // declare numbers as an int array of any size numbers = new int[10]; // numbers is a 10-element array numbers = new int[20]; // now it's a 20-element array 声明数组 C# 支持一维数组、多维数组(矩形数组)和数组的数组(交错的数组)。下面的示例展示如何声明不同类型的数组: 一维数组

leetcode Array problem 905, 977, 830

扶醉桌前 提交于 2020-02-16 22:05:32
905. Sort Array By Parity Given an array A of non-negative integers, return an array consisting of all the even elements of A , followed by all the odd elements of A . You may return any answer array that satisfies this condition. Example 1: Input: [3,1,2,4] Output: [2,4,3,1] The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted. Note: 1 <= A.length <= 5000 0 <= A[i] <= 5000 Time Limit Exceeded: class Solution { public: vector<int> sortArrayByParity(vector<int>& A) { for(int i = 0; i < A.size(); ) { if(A[i]%2 == 1) { A.push_back(A[i]); A.erase(A.begin()+i); } else i++; }

11. Container With Most Water

£可爱£侵袭症+ 提交于 2020-02-16 21:17:12
1.题目描述 英文版: Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not slant the container and n is at least 2. The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49. Example: Input: [1,8,6,2,5,4,8,3,7] Output: 49 中文版: 给n个非负整数a1,a2,a3....

async-validator 的中文文档翻译

混江龙づ霸主 提交于 2020-02-16 17:43:45
阿里出品的 antd 和 ElementUI 组件库中表单校验默认使用的 async-validator ,它在 gitbub 上也获得了 3.8k 的 star,可见这个库十分强大,奈何只有英文文档看的蛋疼,因此花点时间翻译一下以便日后查看和为新手同事提供文档,原文都以折叠的方式保留着,看不懂我的描述可以展开看看原文。 结合 github 上的例子能方便理解 (大部分原因是我英文水平不够,但是明明是中国人写的为啥不顺手写个中文的 readme 呢,虽然就算翻译成了中文也还是晦涩难懂。。。) 翻译时间: 2019/5/31 正文开始。 async-validator 一个用于表单异步校验的库,参考了 https://github.com/freeformsystems/async-validate Validate form asynchronous. A variation of https://github.com/freeformsystems/async-validate API 下述内容来自于 async-validate . 的早期版本 The following is modified from earlier version of async-validate . Usage 使用方法 基本的使用方法:定义一个 descriptor,将它传入 schema,得到一个

01二维数组中的查找

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-15 09:02:48
题目描述 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 思路分析 从右上角的数开始比较,因为他是这行的max,这列的min,若目标数比它小,则往左走;比他大,则往下走。 代码实现 public boolean Find ( int target , int [ ] [ ] array ) { if ( array == null || array . length == 0 || array [ 0 ] . length == 0 || array [ 0 ] == null ) { return false ; } int row = 0 ; int column = array [ 0 ] . length - 1 ; while ( row < array . length && column >= 0 ) { if ( target == array [ row ] [ column ] ) { return true ; } else if ( target > array [ row ] [ column ] ) { row ++ ; } else { column -- ; } } return false ; } 来源:

leetcode刷题笔记(Golang)--80. Remove Duplicates from Sorted Array II

↘锁芯ラ 提交于 2020-02-15 04:40:59
80. Remove Duplicates from Sorted Array II Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Example 1: Given nums = [1,1,1,2,2,3], Your function should return length = 5, with the first five elements of nums being 1, 1, 2, 2 and 3 respectively. It doesn’t matter what you leave beyond the returned length. Example 2: Given nums = [0,0,1,1,1,1,2,3,3], Your function should return length = 7,

LightOJ--1164--区间查询与求和

穿精又带淫゛_ 提交于 2020-02-15 04:05:58
World is getting more evil and it's getting tougher to get into the Evil League of Evil. Since the legendary Bad Horse has retired, now you have to correctly answer the evil questions of Dr. Horrible, who has a PhD in horribleness (but not in Computer Science). You are given an array of n elements, which are initially all 0 . After that you will be given q commands. They are - 1. 0 x y v - you have to add v to all numbers in the range of x to y (inclusive), where x and y are two indexes of the array. 2. 1 x y - output a line containing a single integer which is the sum of all the array