1. # -*- coding: utf-8 -*-
  2. #!/bin/env python
  3. # Python2.7
  4.  
  5. nums = [2, 4, 7, 0, 12, 6]
  6.  
  7. print sorted(range(len(nums)))
  8.  
  9. # ind是 列表nums 排序后值的索引
  10. ind = sorted(range(len(nums)), key=lambda x: nums[x])
  11.  
  12. print ind
  13.  
  14. L = [('b',2),('a',1),('e',3),('d',4)]
  15. print sorted(L)
  16. # 按照列表中的第二项来进行排序
  17. print sorted(L, key=lambda x:x[1])
  18.  
  19. print sorted(L, key=lambda x:x[0])

关键字:sorted two sum

leetcode笔记-1 twosum的更多相关文章

  1. leetcode笔记--1 two-sum

    my answer: ​​​​出现的问题:倒数第二行and i !=s这种情况没有考虑进去,以后要思考全面些

  2. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  3. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  4. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

  5. Leetcode 笔记 100 - Same Tree

    题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...

  6. Leetcode 笔记 99 - Recover Binary Search Tree

    题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...

  7. Leetcode 笔记 98 - Validate Binary Search Tree

    题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...

  8. Leetcode 笔记 101 - Symmetric Tree

    题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, s ...

  9. Leetcode 笔记 36 - Sudoku Solver

    题目链接:Sudoku Solver | LeetCode OJ Write a program to solve a Sudoku puzzle by filling the empty cells ...

随机推荐

  1. 忘记apple id如何更新应用?

    最近ytkah的app有很多更新提示,之前注册的apple id好久没登录了,突然提示说登录需要验证安全问题,哪还记得噢,最要命的是邮箱收到的加密邮件也需要验证.重新注册一个吧,这次要注意保存相关信息 ...

  2. jQuery实现复选框全选/所有取消/反选/获得选择的值

    <!DOCTYPE html> <html> <head> <script type="text/javascript" src=&quo ...

  3. shell if判断-n

    test测试命令 test命令用于检查某个条件是否成立,它可以进行数值.字符串和文件三个方面的测试,其测试符和相应的功能分别如下: (1)数值测试: -eq:等于则为真        -ne:不等于则 ...

  4. linux 如何查找命令的路径

    linux 下,我们常使用 cd ,grep,vi 等命令,有时候我们要查到这些命令所在的位置,如何做呢? linux下有2个命令可完成该功能:which ,whereis which 用来查看当 前 ...

  5. Sqlserver与Mysql触发器之间的差别

    今天练习sqlserver,一开始感觉应该像Oracle,Mysql语法差不多,但是经过一下午的奋战,才感觉原来这三个数据库就是有区别啊, 我原来学习触发器的时候用的是Mysql,感觉还行,但是今天采 ...

  6. Javamail 发送附件中文名过长以及乱码问题

      最近在弄javamail发送邮件当邮件里含有附件并且附件是中文的时候发送后就会出现乱码!! 通过javax.mail.internet.MimeUtility.encodeText()就可解决这个 ...

  7. 每天一个Linux命令(18)loacte命令

    locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.     (1)用法:   用法:  Locate  [选项] [参数]     (2)功能: 功能:  在mlocate数据库中搜索 ...

  8. MD5加密“破解”在.NET平台实现最基本的理解

    MD5作为一种散列算法,广泛用于密码传输过程中的“加密”(引号的意思是这并不是真正的加密,而是形成密码的散列值)过程.MD顾名思义Message Digest(报文摘要),可以将输入的密码,一般来说为 ...

  9. MySQL创建用户并授权及撤销用户权限

    这篇文章主要介绍了MySQL创建用户并授权及撤销用户权限.设置与更改用户密码.删除用户等等,需要的朋友可以参考下 MySQL中创建用户与授权的实现方法. 运行环境:widnows xp profess ...

  10. 剑指offer之 替换空格

    package Problem4; public class ReplaceBank { /* * 题目描述: 请实现一个函数,将字符串的每个空格替换为"%20". * 例如输入& ...