publicfinalclassSystem { //System 类不能被实例化。 privateSystem() {} //在 System 类提供的设施中,有标准输入、标准输出和错误输出流;对外部定义的属性 //和环境变量的访问;加载文件和库的方法;还有快速复制数组的一部分的实用方法。 /** * src and dest都必须是同类型或者可以进行转换类型的数组. * @param src the source array. * @param srcPos starting position in the source array. * @param dest the destination array. * @param destPos starting position in the destination data. * @param length the number of array elements to be copied. */ publicstaticnativevoidarraycopy(Object src, int srcPos, Object dest, int destPos, int length); } package com.lang.reflect;
如果两个指定的 long 型数组彼此相等,则返回 true。如果两个数组包含相同数量的元素,并且两个数组中的所有相应元素对都是相等的,则认为这两个数组是相等的。换句话说,如果两个数组以相同顺序包含相同的元素,则两个数组是相等的。同样的方法适用于所有的其他基本数据类型(Byte,short,Int等)。
public static void fill(int[] a, int val)
将指定的 int 值分配给指定 int 型数组指定范围中的每个元素。同样的方法适用于所有的其他基本数据类型(Byte,short,Int等)。
Write a class StockSpanner which collects daily price quotes for some stock, and returns the span of that stock’s price for the current day.
The span of the stock’s price today is defined as the maximum number of consecutive days (starting from today and going backwards) for which the price of the stock was less than or equal to today’s price.
For example, if the price of a stock over the next 7 days were [100, 80, 60, 70, 60, 75, 85], then the stock spans would be [1, 1, 1, 2, 1, 4, 6].
Example 1:
1 2 3 4 5 6 7 8 9 10 11
Input: ["StockSpanner","next","next","next","next","next","next","next"], [[],[100],[80],[60],[70],[60],[75],[85]] Output: [null,1,1,1,2,1,4,6] Explanation: First, S = StockSpanner() is initialized. Then: S.next(100) is called and returns 1, S.next(80) is called and returns 1, S.next(60) is called and returns 1, S.next(70) is called and returns 2, S.next(60) is called and returns 1, S.next(75) is called and returns 4, S.next(85) is called and returns 6.
Note that (for example) S.next(75) returned 4, because the last 4 prices (including today’s price of 75) were less than or equal to today’s price.
Note:
Calls to StockSpanner.next(int price) will have 1 <= price <= 10^5.
There will be at most 10000 calls to StockSpanner.next per test case.
There will be at most 150000 calls to StockSpanner.next across all test cases.
The total time limit for this problem has been reduced by 75% for C++, and 50% for all other languages.
For DOM elmenets that does simple display, Angular one-way binding is very useful. For example, pure text, or un-editable tables, one-way binding can quick get rendered by directly binding the Angular variable or using *ngFor iteration. There are three examples of one-way binding in the html template. THe binding objective can be expression, which does not change variables.
1 2 3
<p>Hello {{username}}.</p><!-- pure one-way interpolation with {{}} syntax--> <input [value]="username"><!-- DOM property with [] binding --> bind-target="expression" <!-- bind- prefix target binding-->
** Remember to user [] brackets to make the DOM property actively linked with Angular variables, otherwise the binding is worked as string type initialization only.
Angular two-way binding with DOM elements
For DOM elements that also can have user interactions like input elements, select elments, two-way binding or event binding is required to allow Angular know about the user action. The grammar to bind a two-way variable is to use [(target)].
There are some examples of Angular two-way binding:
1 2
<input [(ngModel)]="username"><!-- property, like ngModel for form elements, with [()] syntax--> bindon-target="expression" <!-- bindon- prefix target two-way binding-->
Angular event binding with DOM elements
Some DOM elements are not interact with text but events link click or text change, Angular also provides sytax for event binding so it can track user’s behavior based on DOM events. Vairables, like #event template input variable (let here), and template reference variable (#heroForm), which can be passed to the event handlers. The grammar to bind a event of a DOM is to use parenthesis with Angular event like (click). Event handlers can only be statements like methods of the component instance.
There are some examples of Angular event bindings:
1 2
(click)="click($event)" <!-- use DOM property binding with () syntax--> on-target="statement" <!-- use on- prefix target binding -->
Angular template binding targets
It’s not hard to see, binding targets in Angular includes HTML properties and events as below table.
Type
Target
Examples
Property
Element property, Component property, Directive property
A template reference variable is often a reference to a DOM element within a template. It can also be a reference to an Angular component or directive or a web component. Use the hash symbol (#) to declare a reference variable. The #phone declares a phone variable on an <input> element.
Example:
1 2 3 4
<input #phoneplaceholder="phone number"> <!-- lots of other elements --> <!-- phone refers to the input element; pass its `value` to an event handler --> <button (click)="callPhone(phone.value)">Call</button>
Template expression operators
The template expression language employs a subset of JavaScript syntax supplemented with a few special operators for specific scenarios. The next sections cover two of these operators: pipe and safe navigation operator.
The pipe operator ( | )
Angular pipes are a good choice for small transformations such as these. Pipes are simple functions that accept an input value and return a transformed value. They’re easy to apply within template expressions, using the pipe operator (|):
Example:
1
<div>Title through uppercase pipe: {{title | uppercase}}</div>
The safe navigation operator ( ?. ) and null property paths
The Angular safe navigation operator (?.) is a fluent and convenient way to guard against null and undefined values in property paths. Here it is, protecting against a view render failure if the currentHero is null.
Example:
1
The current hero's name is {{currentHero?.name}}
The Angular non-null assertion operator (!) serves the same purpose in an Angular template.
Example:
1 2 3 4 5
<!--No hero, no text --> <div *ngIf="hero"> The hero's name is {{hero!.name}} </div>
The $any type cast function ($any( ))
Sometimes a binding expression will be reported as a type error and it is not possible or difficult to fully specify the type. To silence the error, you can use the $any cast function to cast the expression to the any type.
1 2 3 4
<!-- Accessing an undeclared member --> <div> The hero's marker is {{$any(hero).marker}} </div>
Angular binding different component properties
We usually binding a template to its own component class. In such binding expressions, the component’s property or method is to the right of the (=).
The Angular compiler won’t bind to properties of a different component unless they are Input or Output properties. You can’t use the TypeScript public and private access modifiers to shape the component’s public binding API.
Declaring Input and Output properties
An Input property is a settable property annotated with an @Input decorator. Values flow into the property when it is data bound with a property binding An Output property is an observable property annotated with an @Output decorator. The property almost always returns an Angular EventEmitter. Values flow out of the component as events bound with an event binding.
Example:
In the sample for this guide, the bindings to HeroDetailComponent do not fail because the data bound properties are annotated with @Input() and @Output() decorators.
In src/app/app.component.html file, below code will through compile error as template of app component does not recognize the property of hero-detail component:
Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple of k, that is, sums up to n*k where n is also an integer.
Example 1:
Input: [23, 2, 4, 6, 7], k=6
Output: True
Explanation: Because [2, 4] is a continuous subarray of size 2 and sums up to 6.
Example 2:
Input: [23, 2, 6, 4, 7], k=6
Output: True
Explanation: Because [23, 2, 6, 4, 7] is an continuous subarray of size 5 and sums up to 42. 42 is a mutiple of 6 and 7 and n=7.
Note:
The length of the array won’t exceed 10,000.
You may assume the sum of all the numbers is in the range of a signed 32-bit integer.
Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.
Example 1:
Input:nums = [1,1,1], k = 2
Output: 2
Note: The length of the array is in range [1, 20,000]. The range of numbers in the array is [-1000, 1000] and the range of the integer k is [-1e7, 1e7].