array

LeetCode 410. Split Array Largest Sum

北城余情 提交于 2020-01-16 13:00:29
原题链接在这里: https://leetcode.com/problems/split-array-largest-sum/ 题目: Given an array which consists of non-negative integers and an integer m , you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these m subarrays. Note: If n is the length of array, assume the following constraints are satisfied: 1 ≤ n ≤ 1000 1 ≤ m ≤ min(50, n ) Examples: Input: nums = [7,2,5,10,8] m = 2 Output: 18 Explanation: There are four ways to split nums into two subarrays. The best way is to split it into [7,2,5] and [10,8], where the largest sum among the

JS版剑指Offer

旧城冷巷雨未停 提交于 2020-01-16 08:43:34
这篇是整理了一部分刷的算法题的大概解题思路,怕自己以后忘记,后续还会更新。 其中解题思路也会在代码中的注释有体现 二维数组中的查找 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 //因为每一行从左到右递增,从上到下递增,所以右上角的数是整个二维数组最大的数 //所以从右上角的数开始比较比target大就行数减一,比target小就列数加一 function Find ( target , array ) { if ( array . length == 0 || array == undefined || array [ 0 ] . length == 0 ) return false ; let rows = array . length ; let cols = array [ 0 ] . length ; let row = 0 ; let col = cols - 1 ; while ( row < rows && col >= 0 ) { if ( array [ row ] [ col ] == target ) return true ; if ( array [ row ] [ col ] > target ) col

Two Arrays

非 Y 不嫁゛ 提交于 2020-01-16 07:19:45
题目 You are given two integers n and m. Calculate the number of pairs of arrays (a,b) such that: the length of both arrays is equal to m; each element of each array is an integer between 1 and n (inclusive); ai≤bi for any index i from 1 to m; array a is sorted in non-descending order; array b is sorted in non-ascending order. As the result can be very large, you should print it modulo 10^9+7. Input The only line contains two integers n and m (1≤n≤1000, 1≤m≤10). Output Print one integer – the number of arrays a and b satisfying the conditions described above modulo 10^9+7. Examples input 2 2

判断某个对象属于哪种数据类型

邮差的信 提交于 2020-01-16 05:46:45
type instanceof Object.prototype.toString.call type 在 JavaScript 里使用 typeof 来判断数据类型,只能区分基本类型,即 “number”,”string”,”undefined”,”boolean”,”object” 五种。 对于数组、函数、对象来说,其关系错综复杂,使用 typeof 都会统一返回 “object” 字符串。 instanceof var a = {}; var b = []; var c = function () {}; //a b c 都是 Object 的实例 console.log(a instanceof Object) //true console.log(b instanceof Object) //true console.log(c instanceof Object) //true //只有 Array 类型的 b 才是 Array 的实例 console.log(a instanceof Array) //false console.log(b instanceof Array) //true console.log(c instanceof Array) //false //只有 Function 类型的 c 才是 Function 的实例 console.log(a

[C++] Array

三世轮回 提交于 2020-01-16 04:45:59
Access the elements of an Array unsinged scores = {1, 2, 3, 4, 5, 6}; for ( auto i:scores){ cout << i << " "; } cout << endl; Becuase the dimension is part of each array type. the system know how many elements are in scores. Pointers and Arrays In C++, pointers and array are closely intertwined. When we use an array, the compiler ordinarily convert the array to a pointer. string nums[] = {"one", "two", "three"}; string *p = &nums[0]; // p points to the first element in nums Arrays have a special property - in most places when we use an array, the comipler automatically substitutes a pointer to

C++:Array

可紊 提交于 2020-01-16 04:45:36
Array是固定大小的容器,定义时要显式的指定大小。 可以修改array中元素的值,但不能向array中插入和删除元素. array在栈上为元素分配内存。 array<TYPE, SIZE> swap(arr1,arr2);  //具有线性时间复杂度 arr1.swap(arr2); .fill(VALUE)  //填充值 .size() Iterators begin Return iterator to beginning (public member function ) end Return iterator to end (public member function ) rbegin Return reverse iterator to reverse beginning (public member function ) rend Return reverse iterator to reverse end (public member function ) cbegin Return const_iterator to beginning (public member function ) cend Return const_iterator to end (public member function ) crbegin Return const_reverse

c++:array

故事扮演 提交于 2020-01-16 04:45:26
#ifndef ARRAY_CLASS #define ARRAY_CLASS #include<iostream> #include<cstdlib> using namespace std; #ifndef NULL #define NULL 0 #endif const enum ErrorType{invalidArraySize, memoryAllocationError, indexOutOfRange}; template <class T> class Array{ private: T * alist; int size; void Error(ErrorType error, int badIndex = 0) const; public: Array(int sz = 50); Array(const Array<T>&A); ~Array(void); Array<T> &operator=(const Array <T> &rhs); T & operator[] (int i); operator T * (void) const; int ListSize(void) const; void Resize(int sz); }; template<class T> void Array<T>::Error(ErrorType error, int

使用python发邮件

狂风中的少年 提交于 2020-01-16 00:19:08
import smtplib from email . mime . text import MIMEText from email . header import Header from email . mime . multipart import MIMEMultipart from email . utils import formataddr import argparse import os import re import subprocess def run ( cnv_vcf , purity , prefix ) : infile = open ( cnv_vcf , "r" ) outfile = open ( "%s.final.CNV.tsv" % ( prefix ) , "w" ) outfile . write ( "#Chr\tStart\tend\tRef\tType\tGene\tCopyNumber\n" ) num = 0 for line in infile : line = line . strip ( ) if not line . startswith ( "#" ) : array = line . split ( "\t" ) if array [ 4 ] == "<DUP>" or array [ 4 ] == "<DEL>"

Java数组排序

血红的双手。 提交于 2020-01-15 19:03:34
**public static void main (string[] args){ //创建数组 int[ ] array = new int [ ]{2,3,4,5,7} //数组 排序 Arrays.sort.of(array); for(int i=0;i<array.length;i++){ system.out.println(array[i]); ** 来源: CSDN 作者: weixin_45963194 链接: https://blog.csdn.net/weixin_45963194/article/details/103993058

1002. Find Common Characters

廉价感情. 提交于 2020-01-15 14:58:42
/** * 1002. Find Common Characters * https://leetcode.com/problems/find-common-characters/submissions/ * Given an array A of strings made only from lowercase letters, * return a list of all characters that show up in all strings within the list (including duplicates). * For example, if a character occurs 3 times in all strings but not 4 times, you need to include that character three times in the final answer. You may return the answer in any order. Example 1: Input: ["bella","label","roller"] Output: ["e","l","l"] * */ class Solution { fun commonChars(A: Array<String>): List<String> { val