亞馬遜面試題及解法


題目:

數組有N+M個數字, 數字的范圍為1 ... N, 打印重復的元素, 要求O(M + N),

可以用額外的空間。

代碼:

private  int[] arr = { 8, 576426893164217};

         private  void button1_Click( object sender, EventArgs e)
        {
             foreach ( int t  in arr)
            {
                 if(arr[Math.Abs(t)]> 0)
                {
                    arr[Math.Abs(t)] = -arr[Math.Abs(t)];
                }
                 else
                {
                    MessageBox.Show(Math.Abs(t).ToString());
                }
            }
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM