--- title: 1502. Can Make Arithmetic Progression From Sequence tags: leetcode,解題報告 --- {%hackmd @hlc23/dark-theme %} # 1502. Can Make Arithmetic Progression From Sequence 題目連結: [Leetcode](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/description/) ## 題目概要 檢查數列是否能排列成等差數列 ## 想法 排序後檢查 ## 參考解法 歡迎補充 :::spoiler CPP 解 ```cpp= class Solution { public: bool canMakeArithmeticProgression(vector<int>& arr) { sort(arr.begin(), arr.end()); int t = arr[1] - arr[0]; for (int i=1; i<arr.size(); i++){ if (arr[i] - arr[i-1] != t) return false; } return true; } }; ``` ::: --- {%hackmd @hlc23/dark-theme-license %}
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up