1、题目

35. Search Insert Position
Easy

1781214Add to ListShare

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

You may assume no duplicates in the array.

Example 1:

Input: [1,3,5,6], 5
Output: 2

Example 2:

Input: [1,3,5,6], 2
Output: 1

Example 3:

Input: [1,3,5,6], 7
Output: 4

Example 4:

Input: [1,3,5,6], 0
Output: 0

2、我的解法

 # -*- coding: utf-8 -*-
# @Time : 2020/2/4 16:33
# @Author : SmartCat0929
# @Email : 1027699719@qq.com
# @Link : https://github.com/SmartCat0929
# @Site :
# @File : 35. Search Insert Position.py
from typing import List
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
lens=len(nums)
if target in nums:
return nums.index(target)
else:
if target < nums[-1]:
for i in range(lens):
if target < nums[i]:
nums.insert(i,target)
return nums.index(target)
else:
return lens
print(Solution().searchInsert([1,4,5,6,11,11],10))
38. Count and Say
Easy

10528180Add to ListShare

The count-and-say sequence is the sequence of integers with the first five terms as following:

1.     1
2. 11
3. 21
4. 1211
5. 111221

1 is read off as "one 1" or 11.
11 is read off as "two 1s" or 21.
21 is read off as "one 2, then one 1" or 1211.

Given an integer n where 1 ≤ n ≤ 30, generate the nth term of the count-and-say sequence. You can do so recursively, in other words from the previous member read off the digits, counting the number of digits in groups of the same digit.

Note: Each term of the sequence of integers will be represented as a string.

Example 1:

Input: 1
Output: "1"
Explanation: This is the base case.

Example 2:

Input: 4
Output: "1211"
Explanation: For n = 3 the term was "21" in which we have two groups "2" and "1", "2" can be read as "12" which means frequency = 1 and value = 2, the same way "1" is read as "11", so the answer is the concatenation of "12" and "11" which is "1211".

最新文章

  1. HHKB MAC 配置指南 操作指南 快捷键
  2. C中的volatile用法
  3. HDU 1231:最大连续子序列 解题报告
  4. 《ASP.NET MVC4 WEB编程》学习笔记------Entity Framework的Database First、Model First和Code Only三种开发模式
  5. C# GUID
  6. 显示标题栏中标题左侧的小图icon
  7. webpack3.x基本配置与总结
  8. 多线程之倒计时器CountDownLatch和循环栅栏CyclicBarrier
  9. Java基础1:深入理解Java面向对象三大特性
  10. The question that comes to mind
  11. bzoj 4540 [HNOI 2016] 序列 - 莫队算法 - Sparse-Table - 单调栈
  12. 关于mysql中使用聚合函数结果集为空,仍显示size为1,所有元素为Null问题的解决办法
  13. 基本select 语句总结
  14. uva-11044-水题
  15. jdk(1.8)命令行工具(二)
  16. QT 主窗口和子窗口相互切换示例
  17. 2017.10.23 Arduino Atmel EFM32低功耗监测
  18. sudo 运行 npm或node时,出现找不到命令
  19. [18/11/29] 继承(extends)和方法的重写(override,不是重载)
  20. [电子书] 《Android编程兵书》PDF

热门文章

  1. 【玩转SpringBoot】SpringBoot应用的启动过程一览表
  2. 数据库之一、数据库简介及SQL概要
  3. go 语言实现栈原理
  4. spring自动装配和通过java实现装配
  5. javascript fp demo
  6. rancher布控集群启动失败的猜测
  7. [C#] 委托与匿名方法
  8. Jenkins Pipeline waitForQualityGate pending 超时
  9. 使用vs进行Nuget打包时的LicenseExpression填写示例参考
  10. 工具 - deepin vscode中的oh-my-zsh乱码