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')

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三種組件。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章