size

4. Median of Two Sorted Arrays

我们两清 提交于 2020-03-27 17:00:58
▶ 问题:求两个已经排好序的数组的中位数。 ▶ 简单的归并版。现将两个数组一趟归并到一个数组中(O(m+n)),再利用新数组长度的奇偶性计算新数组的中位数(O(1)),总体时间复杂度 O(m+n),空间复杂度 O(m+n)。 ● 代码,79 ms 1 class Solution // O(m+n) 2 { 3 public: 4 double findMedianSortedArrays(std::vector<int>& nums1, std::vector<int>& nums2) 5 { 6 std::vector<int>temp; 7 int i, j; 8 for (i = 0, j = 0; i < nums1.size() && j < nums2.size();) // merge common part 9 temp.push_back(nums1[i] < nums2[j] ? nums1[i++] : nums2[j++]); 10 if (i < nums1.size() || j < nums2.size()) // merge rest part 11 { 12 std::vector<int> & ref = (i < nums1.size()) ? nums1 : nums2; 13 for (i = (i < nums1.size()) ? i

CAShaplayer实现一个加载动画

最后都变了- 提交于 2020-03-27 07:19:10
思路: 方法 创建一个图层,图层要求圆形,可传参数颜色、大小 方法 给图层设置位置和整个加载动画的大小 之后给其添加动画,并且注意动画的beginTime要有间距 创建Layer func createLayerWith(size:CGSize,color:UIColor) -> CALayer{ let layer:CAShapeLayer = CAShapeLayer() let path:UIBezierPath = UIBezierPath() //addArcWithCenter,就是根据中心点画圆 /** center:CGPoint 中心点 radius:CGFloat 半径 startAngle:CGFloat 开始的弧度 endAngle:CGFloat 结束的弧度 clockwise:Bool 绘图方向 true:顺时针 false:逆时针 */ path.addArcWithCenter(CGPointMake(size.width/2, size.height/2), radius: size.width/2, startAngle: 0, endAngle: CGFloat(2*M_PI), clockwise: false) layer.lineWidth = 2 layer.fillColor = color.CGColor layer

给视图加上倒影效果

穿精又带淫゛_ 提交于 2020-03-27 06:31:16
给视图加上倒影效果 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 const CGFloat kReflectPercent = - 0 .25f ; const CGFloat kReflectOpacity = 0 .3f ; const CGFloat kReflectDistance = 1 0 .0f ; + ( void ) addSimpleReflectionToView : ( UIView *) theView { CALayer *reflectionLayer = [ CALayer layer ]; reflectionLayer .contents = [theView layer ] .contents ; reflectionLayer .opacity = kReflectOpacity; reflectionLayer .frame = CGRectMake( 0 .0f , 0 .0f , theView .frame .size .width , theView .frame .size .height * kReflectPercent); CATransform3D stransform = CATransform 3 DMakeScale( 1 .0f , - 1 .0f , 1 .0f );

连续子数组的最大和(基于动态规划)

泪湿孤枕 提交于 2020-03-26 12:06:41
题目   输入一个整型数组,数组里有正数也有负数。数组中一个或连续的多个整数组成一个子数组。求所有子数组的和的最大值。 要求时间复杂度为O(n) 。例如输入的数组为{1,-2,3,10,-4,7,2,-5},和最大的子数组为{3,10,-4,7,2},因此输出为该子数组的和18。 思路 一般解法 从头到尾累加数字,保存到一个临时变量curr_sum中 如果前几项的和为负,则加上此和之后比本身的值还要小,抛弃原来所计算得到的和,curr_sum从本元素开始计数 ;否则,把当前元素累加到curr_sum 把curr_sum与最大值max_sum比较(max_sum保存每个连续数组的最大和) class Solution { public: int FindGreatestSumOfSubArray(vector<int> arr) { if(arr.size()==0) return 0; else if(arr.size()==1) return arr[0]; int curSum=arr[0]; int maxSum=-0x3f3f; for(int i=1;i<arr.size();++i) { if(curSum<0)//如果前几项的和为负,则加上此和之后比本身的值还要小,数组从本元素开始计数 curSum=arr[i]; else curSum+=arr[i];

How can I do subplots in matplotlib with differents xlimit and size of axis-x?

余生颓废 提交于 2020-03-26 03:50:49
问题 How can I solve this? I want to do 4 subplots with matplotlib, I have used the subplot option but the result is just a big plot. I don't have idea what is the problem. I want to see four subplots, each one with title, and a suptitle for them. I don't have idea how can I solve it? Can you help me please to fix it? Thanks a lot #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import unicode_literals from matplotlib.collections import LineCollection import matplotlib.patches as

滑动窗口的最大值

浪子不回头ぞ 提交于 2020-03-25 21:43:22
滑动窗口的最大值 题目描述 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值。例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值分别为{4,4,6,6,6,5}; 针对数组{2,3,4,2,6,2,5,1}的滑动窗口有以下6个: {[2,3,4],2,6,2,5,1}, {2,[3,4,2],6,2,5,1}, {2,3,[4,2,6],2,5,1}, {2,3,4,[2,6,2],5,1}, {2,3,4,2,[6,2,5],1}, {2,3,4,2,6,[2,5,1]}。 使用一个队列做小标索引, 保存窗内最大值的下标, 还要判断这个索引是否在当前窗内 class Solution { public: vector<int> maxInWindows(const vector<int>& num, unsigned int size) { vector<int> ret; if ((num.size() >= size ) && (size > 0)) { deque<int> index; // 用于存放下标的索引 for (auto i = 0; i < size; i++) { // 存放前size个中的最大值 // 重复元素只存储一份, 所以用大于等于号 while ((! index.empty(

滑动窗口的最大值

落花浮王杯 提交于 2020-03-25 21:29:38
原文地址: https://www.jianshu.com/p/e9af38e066bf 时间限制:1秒 空间限制:32768K 题目描述 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值。例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值分别为{4,4,6,6,6,5};针对数组{2,3,4,2,6,2,5,1}的滑动窗口有以下6个: {[2,3,4],2,6,2,5,1},{2,[3,4,2],6,2,5,1},{2,3,[4,2,6],2,5,1},{2,3,4,[2,6,2],5,1},{2,3,4,2,[6,2,5],1},{2,3,4,2,6,[2,5,1]}。 我的代码 class Solution { public: vector<int> maxInWindows(const vector<int>& num, unsigned int size) { vector<int> res; int siz=num.size(); if(siz<1 || size<1 || siz<size) return res; if(size==1) return num; deque<int> tmp; for(int i=0;i<size;i++){ while((!tmp.empty())&&(tmp

Elements & MyVector 2016 4 8 homework

大城市里の小女人 提交于 2020-03-23 18:52:26
#include<iostream> #include<string> using namespace std; class Elements{ private: int value; static int numberOfObjects; public: Elements(); Elements(const int &value);//set value Elements(const Elements &elem); ~Elements();//descructor Elements & operator=(const Elements &elem);//assignment Elements & operator=(const int &value);//assignment friend istream& operator>>(istream& is, Elements & elem); //input one integer, and set the value friend ostream& operator<<(ostream& os, const Elements & elem); //output one integer to ostream void setValue(const int &value); //set value int getValue(

中国银行在线支付接口代码

半世苍凉 提交于 2020-03-22 15:04:24
页面代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChinaBank.aspx.cs" Inherits="ChinaBank.ChinaBank" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body onload="javascript:document.frm1.submit();"> <form action="https://ebspay.boc.cn/PGWPortal/RecvOrder.do" method="post" name="frm1" id="frm1"> <div> <!--01.商户号--> <INPUT TYPE="HIDDEN" SIZE="25" ID="merchantNo" NAME="merchantNo" VALUE=""><BR/> <!--02.支付类型--> <INPUT

1001. Elements and MyVector 2016 4 8

时间秒杀一切 提交于 2020-03-21 01:43:27
#include<iostream> #include<string> using namespace std; class Elements{ private: int value; static int numberOfObjects; public: Elements(); Elements(const int &value);//set value Elements(const Elements &elem); ~Elements();//descructor Elements & operator=(const Elements &elem);//assignment Elements & operator=(const int &value);//assignment friend istream& operator>>(istream& is, Elements & elem); //input one integer, and set the value friend ostream& operator<<(ostream& os, const Elements & elem); //output one integer to ostream void setValue(const int &value); //set value int getValue(