LeetCode學習Day2 排序1

2021-10-21 05:55:34 字數 1575 閱讀 7244

3.解題

給定兩個字串 s 和 t ,編寫乙個函式來判斷 t 是否是 s 的字母異位詞。

示例 1:

輸入: s = 「anagram」, t = 「nagaram」

輸出: true

示例 2:

輸入: s = 「rat」, t = 「car」

輸出: false

說明:你可以假設字串只包含小寫字母。

7 string str1 = 「hello」;

8 string* str2 = new string(「hello」);

9 string str3 = 「world」;

1011 //獲取字串長度

12 int length = str1.length();

13 cout << 「呼叫str.length()函式獲取字串長度:」 << length << endl;

14 cout << endl;

17 //字串連線

18 string str4 = str1 + str3;

19 cout << 「字串連線結果:」 << str4 << endl;

20 cout << endl;

23 //字串比較

24 if (str1 < str3)

25 cout << 「字串比較:」 << 「str129 //獲取字串的第乙個字元

30 string::const_iterator it = str1.begin();

31 cout << *it << endl;

32 cout << endl;

35 //獲取字串的最後乙個字元

36 it = str1.end();//end是指向最後乙個字元後面的元素,而且不能輸出,所以cout << *it << endl;這樣輸出會報錯

37 it–;

38 cout << *it << endl;

39 cout << endl;

42 //倒置串

43 reverse(str1.begin(), str1.end());

44 cout << 「倒置串:」 << str1 << endl;

45 cout << endl;

c++標準庫里的排序函式的使用方法

i)sort函式包含在標頭檔案為#include的c++標準庫中,呼叫標準庫里的排序方法可以不必知道其內部是如何實現的,只要出現我們想要的結果即可!

ii)sort函式有三個引數:

(1)第乙個是要排序的陣列的起始位址。

(2)第二個是結束的位址(最後一位要排序的位址)

(3)第三個引數是排序的方法,可以是從大到小也可是從小到大,還可以不寫第三個引數,此時預設的排序方法是從小到大排序。

sort函式使用模板:

sort(start,end,排序方法)

不寫排序方法預設從小到大

#include「iostream」

#include「b;

}sort(a.begin(),b.begin());

先排序再看是否相等
class solution

};

機器學習 day2

歸一化 將所有資料轉化到同一標準下,使的某乙個特徵對最終結果不會造成更大的影響。通過對原始資料進行變換把資料對映到 預設為 0,1 之間 問題 如果資料中異常點過多,會有什麼影響?最大值最小值會受影響。方差考量資料的穩定性。標準化 將所有資料進行變換到平均值為0,標準差為1之間。standardsc...

爬蟲學習Day2

import requests if name main url city input enter a city data headers response requests.post url url,data data,headers headers page text response.text...

機器學習Day2

英文原鏈結源鏈結 假設 x和y是線性相關的 則需要找到乙個關於x的線性函式來盡可能準確的 y。y a0 a1x1 怎樣找到最合適的回歸線?通過最小化 值和觀測值的均方差 導入庫 匯入資料集 檢查缺失資料 分離訓練集和測試集 特徵縮放 從sklearn.linear model中匯入linearreg...