array

[LC] 66. Plus One

纵然是瞬间 提交于 2019-12-04 17:29:20
Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit. You may assume the integer does not contain any leading zero, except the number 0 itself. Example 1: Input: [1,2,3] Output: [1,2,4] Explanation: The array represents the integer 123. Example 2: Input: [4,3,2,1] Output: [4,3,2,2] Explanation: The array represents the integer 4321. class Solution { public int[] plusOne(int[] digits) { if (digits == null || digits

PHP stdclass转array的方法

旧巷老猫 提交于 2019-12-04 17:22:43
PHP stdclass转array的方法 <pre> <?php $a = new stdClass(); $a->id = '11 '; $a->username = 'me'; print_r($a); $b=object2array($a); print_r($b); function object2array($object) { $object1 = json_decode( json_encode( $object),true); return $object1; } ?> </pre> 输出结果 <pre> stdClass Object ( [id] => 11 [username] => me ) Array ( [id] => 11 [username] => me ) </pre> 来源: https://www.cnblogs.com/newmiracle/p/11875323.html

php array_push 与 $arr[]=$value 性能比较

南笙酒味 提交于 2019-12-04 17:22:23
使用array_push压入1000000个元素 <pre> <?php $starttime = get_microtime(); $arr = array(); for($i=0; $i<1000000; $i++){ array_push($arr, $i); } $endtime = get_microtime(); printf("run time %f ms\r\n", ($endtime-$starttime)*1000); function get_microtime(){ list($usec, $sec) = explode(' ', microtime()); return (float)$usec + (float)$sec; } ?> </pre> 执行时间:2735.545158 ms <?php $starttime = get_microtime(); $arr = array(); for($i=0; $i<1000000; $i++){ $arr[] = $i; } $endtime = get_microtime(); printf("run time %f ms\r\n", ($endtime-$starttime)*1000); function get_microtime(){ list($usec, $sec) = explode('

1250. Check If It Is a Good Array

ぐ巨炮叔叔 提交于 2019-12-04 14:55:12
Given an array nums of positive integers. Your task is to select some subset of nums , multiply each element by an integer and add all these numbers. The array is said to be good if you can obtain a sum of 1 from the array by any possible subset and multiplicand. Return True if the array is good otherwise return False . Example 1: Input: nums = [12,5,7,23] Output: true Explanation: Pick numbers 5 and 7. 5*3 + 7*(-2) = 1 Example 2: Input: nums = [29,6,10] Output: true Explanation: Pick numbers 29, 6 and 10. 29*1 + 6*(-3) + 10*(-1) = 1 Example 3: Input: nums = [3,6] Output: false Constraints: 1

PHP str_replace的用法

廉价感情. 提交于 2019-12-04 13:21:28
PHP str_replace的用法 1 替换单个字符 <pre> <?php echo str_replace("world","Shanghai","Hello world!"); ?> </pre> <pre> //结果 Hello Shanghai! </pre> 2 多个字符替换多个字符 <pre> $result=str_replace(array(1,2,3), array(3,4,5), "good5 golly2 miss3 molly!"); echo $result; </pre> <pre> //结果 good5 golly4 miss5 molly! </pre> 3 如果碰到 要匹配的是相同的可以采取如下方法 <pre> <?php $pattern = array('/a/', '/a/', '/a/'); $replacement = array('x', 'y', 'z'); $subject = 'abcadeafg'; $res = preg_replace($pattern, $replacement, $subject , 1); echo $res; // xbcydezfg $pattern = array('/\?/', '/\?/', '/\?/'); $replacement = array('x', 'y', 'z');

NumPy 之 案例(随机漫步)

老子叫甜甜 提交于 2019-12-04 12:15:44
import numpy as np The numpy.random module supplements(补充) the built-in Python random with functions for efficiently generating whole arrays of sample values from many kinds of probalility distributions. For example, you can get a 4x4 array of samples from the standard normal distribution using normal: samples = np.random.normal(size=(4,4)) samples array([[-0.49777854, 1.01894039, 0.3542692 , 1.0187122 ], [-0.07139068, -0.44245259, -2.05535526, 0.49974435], [ 0.80183078, -0.11299759, 1.22759314, 1.37571884], [ 0.32086762, -0.79930024, -0.31965109, 0.23004107]]) Python's built-in random module,

Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray 水题

試著忘記壹切 提交于 2019-12-04 11:40:45
C. Dominated Subarray Let's call an array 𝑡 dominated by value 𝑣 in the next situation. At first, array 𝑡 should have at least 2 elements. Now, let's calculate number of occurrences of each number 𝑛𝑢𝑚 in 𝑡 and define it as 𝑜𝑐𝑐(𝑛𝑢𝑚). Then 𝑡 is dominated (by 𝑣) if (and only if) 𝑜𝑐𝑐(𝑣)>𝑜𝑐𝑐(𝑣′) for any other number 𝑣′. For example, arrays [1,2,3,4,5,2], [11,11] and [3,2,3,2,3] are dominated (by 2, 11 and 3 respectevitely) but arrays [3], [1,2] and [3,3,2,2,1] are not. Small remark: since any array can be dominated only by one number, we can not specify this number and just say that array is either

八皇后问题

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 09:25:00
public class EightQueenDemo { public static int count = 0; public boolean check(int array[][], int num, int i, int j) { //每行每列都只有一个棋子 for(int k = 0; k < num; k++) { if(array[i][k] == 1) return false; if(array[k][j] == 1) return false; } /*把i和j的值分别置为比当前棋子位置的值少一,即为左上角一格, i >= 0 && j >= 0;控制i和j在棋盘范围内, --i, --j;向左上角移动 */ for(int s = i - 1, t = j - 1; s >= 0 && t >= 0; s--, t--) { if(array[s][t] == 1) return false; } /*i的值为当前棋子的行值减一,j的值为当前棋子的列值加一,即为右上角一格, i != N && j != N; 控制i和j在棋盘范围内, --i, ++j;向右上角移动 */ for(int s = i - 1, t = j + 1; s >= 0 && t < num; s--, t++) { if(array[s][t] == 1) return false;

《串并行数据结构与算法(SML语言)实验》题解

江枫思渺然 提交于 2019-12-04 05:47:02
注意:本题解仅供参考学习,请勿直接抄袭代码,否则造成的后果和笔者无关。 第一题: 题意: 对n个数升序排序。 题解: 快排,不解释。 代码(省略了输入输出函数,下同): 1 val n = getInt (); 2 val l = getIntTable (n); 3 fun qsort [] = [] 4 | qsort l' = let 5 val p = hd l'; 6 val l1 = List.filter (fn x => x < p) l'; 7 val l2 = List.filter (fn x => x = p) l'; 8 val l3 = List.filter (fn x => x > p) l'; 9 in qsort(l1) @ l2 @ qsort(l3) end; 10 printIntTable (qsort l); 第二题: 题意: 单源最短路,点数1000以内,边数3000以内。 题解: 实在想不出SML语言怎么写邻接表,考虑到点数只有1000,所以直接用邻接矩阵,既然如此,优先队列优化也不带了,O(n 2 )水过。 代码: 1 val inf = 0x3fffffff; 2 val n = getInt() and m = getInt() and s = getInt() - 1; 3 val g = Array2.array (n,

【大数据技术能力提升_2】numpy学习

霸气de小男生 提交于 2019-12-04 04:58:15
numpy学习 标签(空格分隔): numpy python 数据类型 5种类型:布尔值(bool),整数(int),无符号整数(uint)、浮点(float)、复数(complex) 支持的原始类型与 C 中的原始类型紧密相关: Numpy 的类型 C 的类型 描述 np.bool bool 存储为字节的布尔值(True或False) np.byte signed char 平台定义 np.ubyte unsigned char 平台定义 np.short short 平台定义 np.ushort unsigned short 平台定义 np.intc int 平台定义 np.uintc unsigned int 平台定义 np.int_ long 平台定义 np.uint unsigned long 平台定义 np.longlong long long 平台定义 np.ulonglong unsigned long long 平台定义 np.half / np.float16 - 半精度浮点数:符号位,5位指数,10位尾数 np.single float 平台定义的单精度浮点数:通常为符号位,8位指数,23位尾数 np.double double 平台定义的双精度浮点数:通常为符号位,11位指数,52位尾数。 np.longdouble long double np