<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 查找數組中非重復(不同)元素的總和 > 原文: [https://www.geeksforgeeks.org/find-sum-non-repeating-distinct-elements-array/](https://www.geeksforgeeks.org/find-sum-non-repeating-distinct-elements-array/) 給定一個具有重復元素的整數數組,任務是查找數組中所有不同元素的總和。 **示例**: ``` Input : arr[] = {12, 10, 9, 45, 2, 10, 10, 45,10}; Output : 78 Here we take 12, 10, 9, 45, 2 for sum because it's distinct elements Input : arr[] = {1, 10, 9, 4, 2, 10, 10, 45 , 4}; Output : 71 ``` **簡單解決方案**是使用兩個嵌套循環。 外循環從最左邊的元素開始一個接一個地選擇一個元素。 內部循環檢查元素的左側是否存在。 如果存在,則忽略該元素。 **時間復雜度**: `O(n^2)` **輔助空間**:`O(1)` 這個問題的**更好的解決方案**是,使用排序技術,我們首先按升序對數組的所有元素進行排序,然后在數組中逐個查找不同的元素。 ## C++ ```cpp // C++ Find the sum of all non-repeated // elements in an array #include<bits/stdc++.h> using namespace std; // Find the sum of all non-repeated elements // in an array int findSum(int arr[], int n) { ????// sort all elements of array ????sort(arr, arr + n); ????int sum = 0; ????for (int i=0; i<n; i++) ????{ ????????if (arr[i] != arr[i+1]) ????????????sum = sum + arr[i]; ????} ????return sum; } // Driver code int main() { ????int arr[] = {1, 2, 3, 1, 1, 4, 5, 6}; ????int n = sizeof(arr)/sizeof(int); ????cout << findSum(arr, n); ????return 0; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看