(python)leetcode刷题笔记 01 TWO SUM
1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
Given nums = [, , , ], target = , Because nums[] + nums[] = + = ,
return [, ].
ANSWER:
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
for i, v1 in enumerate(nums):
for j, v2 in enumerate(nums[i + :]):
if (v1 + v2) == target:
return [i,j+i+]
ANSWER
(python)leetcode刷题笔记 01 TWO SUM的更多相关文章
- 【leetcode刷题笔记】Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...
- 【leetcode刷题笔记】Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- (python)leetcode刷题笔记03 Longest Substring Without Repeating Characters
3. Longest Substring Without Repeating Characters Given a string, find the length of the longest sub ...
- (python)leetcode刷题笔记05 Longest Palindromic Substring
5. Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You ...
- (python)leetcode刷题笔记04 Median of Two Sorted Arrays
4. Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of size m and n respectiv ...
- 【leetcode刷题笔记】Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number. The ...
- 【leetcode刷题笔记】Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...
- 18.9.10 LeetCode刷题笔记
本人算法还是比较菜的,因此大部分在刷基础题,高手勿喷 选择Python进行刷题,因为坑少,所以不太想用CPP: 1.买股票的最佳时期2 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. ...
- LeetCode刷题笔记和想法(C++)
主要用于记录在LeetCode刷题的过程中学习到的一些思想和自己的想法,希望通过leetcode提升自己的编程素养 :p 高效leetcode刷题小诀窍(这只是目前对我自己而言的小方法,之后会根据自己 ...
随机推荐
- JAVA交通规则
第一个JAVA程序的编写和运行 1.使用记事本编辑: public class Welcome { public static void main(String[] args) { System.ou ...
- 关于ORA-00257: archiver error. Connect internal only, until freed 错误的处理方法
转 关于ORA-00257: archiver error. Connect internal only, until freed 错误的处理方法 2016年03月31日 10:14:59 阅读数:1 ...
- js浮点型,整型操作方法汇总(进行中)
浮点数操作方法如下: 1. Math.ceil()用作向上取整.(ceil 天花板) 2. Math.floor()用作向下取整. (floor 地板) (js 中取整底层原理是位运算的取反~运算,运 ...
- xtrabackup全量备份+binlog基于时间点恢复
1.通过xtrabackup的备份恢复数据库. 2.找到start-position和binlog名称 cat xtrabackup_info 3.导出mysqlbinlog为sql文件,并确定恢复的 ...
- 判断ARP欺骗
转自http://bbs.51cto.com/thread-904594-1.html 网关是服务器或者单独主机设备的话 如果网关是服务器或者单独主机设备的话查询网关MAC地址要简单一些,我们只需要在 ...
- shell习题第1题:每日一文件
[题目要求] 请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件 例如生成的文件为2019-04-25.log,并且把磁盘使用情况写入到这个文件中 不用考虑cron,仅仅写脚本即可 [核心要 ...
- linux命令sed与awk是干什么用的,怎么用?
非常强大的文本操纵工具,sed,awk,grep 这个三个命令 都是操作文本文件的unix系统有几个非常命令的特点:1. 对于内核而言,unix文件都是字节序列.io设备也是文件.2. 至于文件的含义 ...
- MapReduce之Map Join
一 介绍 之所以存在Reduce Join,是因为在map阶段不能获取所有需要的join字段,即:同一个key对应的字段可能位于不同map中.Reduce side join是非常低效的,因为shuf ...
- opencv3 学习四 - 图像减色
程序如下 #include "opencv2/opencv.hpp" using namespace cv; int main() { // 灰度图 Mat original = ...
- 对fgets的理解
gets()函数 因为用gets函数输入数组时,只知道数组开始处,不知道数组有多少个元素,输入字符过长,会导致缓冲区溢出,多余字符可能占用未使用的内存,也可能擦掉程序中的其他数据,后续用fgets函数 ...