target

1.两数之和

爷,独闯天下 提交于 2020-02-20 08:03:49
给定一个整数组nums和一个目标target,请你在该数组中找出和为目标值的那两个整数,并返回他们的数组下标。 示例 : 给定nums = [2,7,11,15],target=9,因为nums[]+nums[]=2+7=9,所以返回[0,1] 在这里我给出我的python的方法和代码。 方法一 : 暴力破解 对于这个问题我第一想法,遍历数组得到数组的值和他的下标,分别为( i,value),然后从nums的j = i+1遍历数组,进行判断是否存在等于y = target - value的元素 def twoSum ( sums , target ) : length = len ( nums ) #获取数组的长度 for i , x in enumerate ( nums ) : #i是数组的下标,value是数组的元素 y = target - x j = x + 1 #为了避免重复,我们从第i+1项开始 while j < length : if ( nums [ j ] == y ) : return [ i , j ] #如果存在则返回对应元素的下标 j += 1 方法二 : 哈希表 暴力破解的随说简单,但时间复杂度为O(n*n),所以我们考虑用神办法能够降低时间复杂度,所以考虑用哈希表来解决问题

自定义注解

Deadly 提交于 2020-02-20 05:02:14
如果要自定义一个注解,首先要明白注解怎样定义,也就是注解定义时的格式。 先来看一个Spring框架的注解@Component。 可以看到,定义注解有两个关键点:元注解、方法(在注解中又叫属性)。 注解的属性(接口中的方法) 一直都在强调,注解的本质是接口,所以,它的内部可以声明方法,在注解中,这些方法又叫做属性。 public @interface TestAnnotation { String value(); } 声明这个方法(属性)又有什么用?为了探究它有什么用,先使用一下这个注解。 报错的原因是没有给value这个属性赋值,所以要给它赋值 再次返回到注解的定义中,看到value方法的返回值类型是String。在使用时(赋值时),要与方法返回值的类型一致。 如果注解只有一个属性,并且这个属性的名称是value,则在使用时,可以在括号中直接写值。 也就是说,对于上面的例子,可以这样使用 @Target("hello") //等价于@Target(value = "hello") 除此之外,还可以设置方法返回默认值,也就是这个属性的默认值。 public @interface TestAnnotation { String value() default "hello"; } 在方法声明后跟上default关键字,在default关键字后加上默认的返回值(或者说是默认的属性值)。

C# IL 指令集

耗尽温柔 提交于 2020-02-19 17:31:41
This is a list of the instructions in the instruction set of the Common Intermediate Language bytecode. Opcode Instruction Description Type of instruction 0x58 add Add two values, returning a new value. Base instruction 0xD6 add.ovf Add signed integer values with ov er f low check. Base instruction 0xD7 add.ovf.un Add unsigned integer values with ov er f low check. Base instruction 0x5F and Bitwise AND of two integral values, returns an integral value. Base instruction 0xFE 0x00 arglist Return arg ument list handle for the current method. Base instruction 0x3B beq <int32 (target)> B ranch to

配置文件编译问题:扫描包的问题 和 编译字符编码问题 和编译器版本1.5问题

非 Y 不嫁゛ 提交于 2020-02-19 14:46:21
配置文件编译问题:扫描包的问题 和 编译字符编码问题 和编译器版本1.5问题<build > <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <encoding>utf-8<

下拉菜单

眉间皱痕 提交于 2020-02-19 14:21:09
<html> <head> <title>下拉式导航菜单</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body bgcolor="#FFFFFF" text="#000000" background="../image/bj.jpg"> <script> function hideAll() { for(i=0;i<odiv.length;i++) { odiv[i].style.display="none"; } } function showObj(num) { if (odiv[num].style.display=="none") { hideAll(); odiv[num].style.display="inline"; } else { odiv[num].style.display="none"; } } </script> <table width="500" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCFFFF"> <tr> <td><table width="200"> <tr > <td> <a href="#" onclick=

LeetCode 240 - 搜索二维矩阵 II

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-19 07:53:37
编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target。该矩阵具有以下特性: 每行的元素从左到右升序排列。 每列的元素从上到下升序排列。 示例: 现有矩阵 matrix 如下: [ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19], [3, 6, 9, 16, 22], [10, 13, 14, 17, 24], [18, 21, 23, 26, 30] ] 给定 target = 5,返回 true。 给定 target = 20,返回 false。 初始坐标 $(i,j)$ 设定为最右上角,如果 $target<mat[i][j]$,那么坐标往左平移一格,因为这一列上的数字都大于 $target$;如果 $target>mat[i][j]$,则坐标往下平移一格,因为这一行上的数字都小于 $target$。 AC代码: class Solution { public: bool searchMatrix(const vector<vector<int>>& mat,int x) { if(mat.empty()) return 0; int i=0, j=mat[0].size()-1; while(i<mat.size() && j>=0) { if(x==mat[i][j]) return 1; else if(x

数据结构与算法——作业1

ぃ、小莉子 提交于 2020-02-19 07:16:02
作业: 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。 你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。 示例: 给定 nums = [2, 7, 11, 15], target = 9 因为 nums[0] + nums[1] = 2 + 7 = 9 所以返回 [0, 1] 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/two-sum 代码: nums = [ 2 , 7 , 11 , 15 ] target = 9 输入数组和目标值 n = len ( nums ) 取数组长度 for j in range ( n ) : 迭代 for i in range ( j + 1 , n ) : 题目要求不能重复使用相同元素 if ( nums [ i ] + nums [ j ] == target ) : print ( [ i , j ] ) 判断 得到结果: C : \Users\Alicerain\AppData\Local\Programs\Python\Python37\python . exe C : / Users / Alicerain / PycharmProjects / untitled5 /

24二叉树中的和为某值的路径

▼魔方 西西 提交于 2020-02-19 07:13:52
题目描述 输入一颗二叉树的根节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。(注意: 在返回值的list中,数组长度大的数组靠前) 思路分析 递归遍历树, 把结点加入路径。若该结点是叶子结点且当前路径和等于期待和,则将此路径加入返回的lists中,否则退回父结点。在每一轮递归返回到父结点时,当前路径也要回溯一个结点值。 代码实现 public ArrayList < ArrayList < Integer > > FindPath ( TreeNode root , int target ) { ArrayList < ArrayList < Integer > > arrayLists = new ArrayList < > ( ) ; if ( root == null || root . val > target ) { return arrayLists ; } arrayLists = process ( root , target , arrayLists , new ArrayList < Integer > ( ) ) ; return arrayLists ; } public ArrayList < ArrayList < Integer > > process (

二维数组中的查找

假装没事ソ 提交于 2020-02-19 05:49:05
在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 class Solution : # array 二维列表 def Find ( self , target , array ) : # write code here rows = len ( array ) - 1 cols = len ( array [ 0 ] ) - 1 i = rows j = 0 while j <= cols and i >= 0 : if target < array [ i ] [ j ] : i -= 1 elif target > array [ i ] [ j ] : j += 1 else : return True return False 从左下角元素往上查找,右边元素是比这个元素大,上边是的元素比这个元素小。于是,target比这个元素小就往上找,比这个元素大就往右找。如果出了边界,则说明二维数组中不存在target元素。 表示形式中 列表list是没有shape属性的,需要将其转换为数组 import numpy as np array = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ] a = len ( array

HTML链接相关属性的使用

半腔热情 提交于 2020-02-19 04:18:04
media属性 功能: 规定url是为什么类型的媒介/设备进行优化的,该属性用于规定目标url是为特殊设备,语音,或打印媒介设计的。media只能在href属性存在时使用。 <link rel="stylesheet" href="..." media="print"> type属性 area元素中的type属性功能: 规定目标url的mime类型,仅在href属性存在时使用,mime是指多用途互联网邮件扩展,它是一个互联网标准。 <area type="value"> w3c标准给出的type的value值为mime_type,目前还有一种用法中value值为image/gif sizes属性 link元素中的sizes属性功能: sizes是link元素新增的属性,该属性可以与icon元素结合使用(通过rel属性),该属性指定关联图标(icon元素)的大小。例如:sizes=“16 X 16”。sizes只有当被链接资源是图标时(rel=“icon”),才能使用该属性 target属性 base元素中的target属性功能: target是base元素新增的属性,主要目的是保持与a元素的一致性。 <head> <base href="http://www.baidu.com" target="_blank"> </head> <body> <a href="">点我</a>