array

896. Monotonic Array*

邮差的信 提交于 2020-01-01 02:42:11
896. Monotonic Array* https://leetcode.com/problems/monotonic-array/ 题目描述 An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is monotone increasing if for all i <= j, A[i] <= A[j] . An array A is monotone decreasing if for all i <= j, A[i] >= A[j] . Return true if and only if the given array A is monotonic. Example 1: Input: [ 1,2,2,3 ] Output: true Example 2: Input: [ 6,5,4,4 ] Output: true Example 3: Input: [ 1,3,2 ] Output: false Example 4: Input: [ 1,2,4,5 ] Output: true Example 5: Input: [ 1,1,1 ] Output: true Note: 1 <= A.length <= 50000 -100000

rust笔记1

有些话、适合烂在心里 提交于 2019-12-31 21:23:39
1. 作用域 fn main ( ) { let a = "JOJO" ; { let a = "DOI" ; println ! ( "{}" , a ) } println ! ( "{}" , a ) } 2.常用类型 [T, N] : 拥有类型T, N个元素的数组 数组 array let mut array : [ i32 ; 4 ] = [ 0 ; 4 ] ; array [ 1 ] = 10 ; for x in & array { println ! ( "{}" , x ) ; } 向量 vec //创建空vec let v : Vec < i32 > = Vec : : new ( ) ; //宏创建vec let v : Vec < i32 > = vec ! [ ] ; //创建可变vec let mut v = vec ! [ 1 , 2 , 3 ] ; v . push ( 10 ) ; let e = v . pop ( ) ; v [ 2 ] = v [ 2 ] + 10 ; str String即 vec:Vec let mut s = String : : new ( ) ; let mut hello = String : : from ( "world" ) ; s . push ( 'w' ) ; s . push_str (

js判断对象类型

北城余情 提交于 2019-12-31 04:30:02
1.typeof typeof只能判断区分基本类型,number、string、boolean、undefined和object,function; typeof 0; //number; typeof true; //boolean; typeof undefined; //undefined; typeof "hello world" //string; typeof function(){}; //function; typeof null; //object typeof {}; //object; typeof []; //object 从上例我们可以看出, typeof 判断对象和数组都返回object,因此它无法区分对象和数组。 2.instanceof var a={}; a instanceof Object //true a intanceof Array //false var b=[]; b instanceof Array //true b instanceof Object //true 因为数组属于object中的一种,所以数组instanceof object,也是true. var c='abc'; c instanceof String; //false var d=new String(); d instanceof String //true

LeetCode 16. 3Sum Closest. (最接近的三数之和)

南笙酒味 提交于 2019-12-30 22:53:25
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. For example, given array S = {-1 2 1 -4}, and target = 1. The sum that is closest to the target is 2. (-1 + 2 + 1 = 2). 题目标签:Array   这道题目给了我们一个nums array 和一个 target, 让我们找到一组三数之和,并且是最接近于target的。由于我们做过了三数之和,所以差不多是一样方法来做这道题(这里充分说明了,要老老实实顺着题号做下去,较先的题目都可以被用来辅助之后的题)。方法就是先sort一下array,为啥要sort呢,因为要用到two pointers 来遍历找两数之和,只有在从小到大排序之后的结果上,才能根据情况移动left 和right。 当确定好了第一个数字后,就在剩下的array里找两数之和

Yii 多表关联relations

六月ゝ 毕业季﹏ 提交于 2019-12-30 22:27:38
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1,首先多表关联是在models/xx.php的relations里配置的。而且是互配,但有区别。 格式: 'VarName'=>array('RelationType', 'ClassName', 'ForeignKey', ...additional options) 需要弄清楚的几点: 1,VarName指什么? 详见下面例2。 2,RelationType。一共有4种,分别为self::HAS_MANY, self::BELONGS_TO, self::MANY_MANY, self::HAS_ONE。 3,ClassName。即关联的另一个../model/类名.php。 4,ForeignKey。谁是谁的外键?写了是用主键关联,为空两个表不是用主键关联需要on 5,附加条件 两个表不是用主键关联 'user' => array(self::BELONGS_TO, 'OaskUser', '' ,'on'=>'name=userName' , 'select'=>'TrueName'),'varchar'=>array(self::HAS_ONE, 'CustomerEntityVarchar', 'entity_id','select'=>'varchar.value','on'=>'varchar

Python-Numpy函数-tile函数

故事扮演 提交于 2019-12-30 20:32:00
tile函数位于python模块 numpy.lib.shape_base中,他的功能是重复某个数组。比如tile(A,n),功能是将数组A重复n次,构成一个新的数组,我们还是使用具体的例子来说明问题: 先来引入numpy下的所有方法 我们创建一个a,如图下图,使用tile来创建b,注意看b的数据结构 假如我们输入一个元组(1,2),我们会得到一样的结果,与上面相同的b 当然,我们想要a变为一个二维数组,就要换一种重复的方式了。 b = tile(a,(m,n)):即是把a数组里面的元素复制n次放进一个数组c中,然后再把数组c复制m次放进一个数组b中 1.tile函数的定义与说明    函数格式tile(A,reps)   A和reps都是array_like   A的类型众多,几乎所有类型都可以:array, list, tuple, dict, matrix以及基本数据类型int, string, float以及bool类型。   reps的类型也很多,可以是tuple,list, dict, array, int, bool.但不可以是float, string, matrix类型。 2.函数操作示例 >>> tile(1,2) array([1, 1]) >>> tile((1,2,3),3) array([1, 2, 3, 1, 2, 3, 1, 2, 3]) >>>

python函数简记

一世执手 提交于 2019-12-30 20:31:47
1. shape函数是numpy.core.fromnumeric中的函数,它的功能是查看矩阵或者数组的维数。 >>> e = eye(3) >>> e array([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]]) >>> e.shape (3, 3) >>> c = array([[1,1],[1,2],[1,3],[1,4]]) >>> c.shape (4, 2) >>> c.shape[0] 4 >>> c.shape[1] 2 2.tile 函数 tile函数是模板numpy.lib.shape_base中的函数。函数的形式是tile(A,reps) A的类型几乎所有类型都可以:array, list, tuple, dict, matrix以及基本数据类型int, string, float以及bool类型。 reps的类型也很多,可以是tuple,list, dict, array, int,bool.但不可以是float, string, matrix类型。行列重复copy的次数。 >>> tile(3,2) array([ 3, 3]) >>> tile((1,2,3),2) array([1, 2, 3, 1, 2, 3]) >>> a=[[1,2,3],[4,5,5]] >>> tile(a,2) array([[1

错题本

爷,独闯天下 提交于 2019-12-30 04:29:38
错题本 1、数组 1-5 对于已正确定义的二维数组a, *(a[i]+j)与a[i][j]的含义相同。 (2分) T (F) 评测结果:答案错误(0 分) 1-7 数组名就是一个指针常量,指向数组的首元素(或者说代表了数组的首地址)。 (2分) (T) F 评测结果:答案错误(0 分) 1-10 假设有定义如下: int array[10]; 则该语句定义了一个数组array。其中array的类型是整型指针(即: int *)。 (2分) (T ) F 评测结果:答案错误(0 分) 来源: CSDN 作者: no1304870436 链接: https://blog.csdn.net/no1304870436/article/details/103757198

LeetCode_496. Next Greater Element I

蓝咒 提交于 2019-12-30 01:30:05
496. Next Greater Element I Easy You are given two arrays (without duplicates) nums1 and nums2 where nums1 ’s elements are subset of nums2 . Find all the next greater numbers for nums1 's elements in the corresponding places of nums2 . The Next Greater Number of a number x in nums1 is the first greater number to its right in nums2 . If it does not exist, output -1 for this number. Example 1: Input: nums1 = [4,1,2], nums2 = [1,3,4,2]. Output: [-1,3,-1] Explanation: For number 4 in the first array, you cannot find the next greater number for it in the second array, so output -1. For number 1 in

ThinkPHP3快速入门教程三:查询语言

限于喜欢 提交于 2019-12-29 16:57:17
一、查询语言简介: ThinkPHP 内置了非常灵活的查询方法,可以快速的进行数据查询操作,查询条件可以用于读取、更新和删除等操作,主要涉及到 where 方法等连贯相关方法操作即可, 此框架查询系统可以解决不同数据库的差异性,因些我们把框架的这一查询方式称之为查询语言。使其查询操作更加简单易懂。 二、查询方式: ThinkPHP 可以支持直接使用字符串作为查询条件,但是大多数情况推荐使用索引数组或者对象来作为查询条件,因为会更加安全。 1、 使用字符串作为查询条件 (最传统的方式,但是安全性不高),例如: $User = M(“User”); // 实例化 User 对象 $User -> where(‘type=1 AND status=1’) -> select(); 生成 SQL 语句: SELECT *FORM think_user WHERE type=1 AND status=1; 注意:采用字符串查询的时候,我们可以配合使用新版提供的字符串条件的安全预处理机制。 2、 使用数组作为查询条件 这种方式是最常用的查询方式,例如: $User = M( “User”); // 实例化 User 对象 $condition[‘name’] =’thinkphp’; $condition[‘status’] = 1; // 把查询条件传入查询方法 $user -> where