ARTS-07-29-2019-08-04

算法练习

集合 S 包含从1到 n 的整数。不幸的是,因为数据错误,导致集合里面某一个元素复制了成了集合里面的另外一个元素的值,导致集合丢失了一个整数并且有一个元素重复。

给定一个数组 nums 代表了集合 S 发生错误后的结果。你的任务是首先寻找到重复出现的整数,再找到丢失的整数,将它们以数组的形式返回。

示例 1:

输入: nums = [1,2,2,4]
输出: [2,3]
注意:

给定数组的长度范围是 [2, 10000]。
给定的数组是无序的。

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/set-mismatch
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

思路

分两步完成
1 寻找重复的元素
2 寻找丢失的整数
1到 n 的整数 作为集合元素,设数组集合为 list,每个元素值为整数,遍历整数,为list的元素赋值,如果元素值已存在,则此元素就是重复的元素。如果集合中的元素值为0,则索引即为缺失的整数。

class Solution(object):
    def findErrorNums(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        n = [0 for i in range(1, len(nums) + 1)]
        
        res = list()
        for i, digit in enumerate(nums):
            if n[digit - 1] == 0:
                n[digit - 1] = digit
            else:
                res.append(digit)
                
        for i, x in enumerate(n):
            if x == 0:
                res.append(i + 1)
                break
                

参考链接 https://blog.csdn.net/qq_32424059/article/details/89059264

英语阅读

Understanding the Python Traceback

Understanding the Python Traceback

文中主要介绍了Python的异常链路输出,以及常见的错误类型,下图是一张典型的Traceback结构。

# example.py
def greet(someone):
  print('Hello, ' + someon)

greet('Chad')
ARTS-07-29-2019-08-04_第1张图片
Traceback.png

Blue box:

The last line of the traceback is the error message line. It contains the exception name that was raised.

Green box:

After the exception name is the error message. This message usually contains helpful information for understanding the reason for the exception being raised.

Yellow box:

Further up the traceback are the various function calls moving from bottom to top, most recent to least recent. These calls are represented by two-line entries for each call. The first line of each call contains information like the file name, line number, and module name, all specifying where the code can be found.

Red underline:

The second line for these calls contains the actual code that was executed.

技巧呈现

PHP生命周期进阶-换个角度看一看

这篇文章适合有一定经验的PHP开发者阅读,介绍了三种PHP的web模型,同时给出了Swool扩展的安装方法。

文章分享

VsCode 扩展巡礼-REST Client

RestClient是VsCode商店的http访问扩展,官方地址 RestClient,用于模拟Http请求。

官方介绍中关注两点

1 基本的Http请求模拟,Http输入和Http响应
2 VsCode自带的辅助功能,如自动补全Http Content-Type等

本篇文章从VsCode下的扩展REST Client入手,通过对基本概念,优势和常用使用场景的介绍,结合Http请求中关于Content-Type的使用注意事项,对常见的接口调用问题进行了梳理。顺便引出访问接口使用的Curl,Zend,Guzzle三种组件。

你可能感兴趣的:(ARTS-07-29-2019-08-04)