發表文章

[LeetCode] Rank Scores

SELECT m . Score      , Rank FROM Scores m JOIN ( SELECT Score AS 'Score'            , ROW_NUMBER () OVER ( ORDER BY Score DESC ) AS RANK         FROM ( SELECT DISTINCT Score                  from Scores ) r ) r1   ON m . Score = r1 . Score ORDER BY r1 . Rank Runtime :  1348 ms , faster than  26.61%  of MS SQL Server online submissions for Rank Scores. ------------------------------------------------------------------------ 似乎不好,但簡單的寫法,歡迎大家流言討論,讓你我更好。

[LeetCode] Exchange Seats

   SELECT m . id         , IFNULL ( IF ( ( m . id & 0x1 ) = 1 , r1 . student , r2 . student ), m . student ) AS 'Student'      FROM seat m LEFT JOIN seat r1        ON r1 . id = ( m . id + 1 ) LEFT JOIN seat r2        ON r2 . id = ( m . id - 1 )     ORDER BY id Runtime :  166 ms , faster than  58.92%  of MySQL online submissions for Exchange Seats. ------------------------------------------------------------------------ 似乎不好,但簡單的寫法,歡迎大家流言討論,讓你我更好。

[LeetCode] Robot Return to Origin

  public class Solution {       public bool JudgeCircle( string moves)       {           var ms = moves.ToArray();           int Y = ms.Count(c => c == 'U' ) - ms.Count(c => c == 'D' );           int X = ms.Count(c => c == 'L' ) - ms.Count(c => c == 'R' );           return X == 0 && Y == 0;       } } Runtime:  108 ms , faster than  9.14%  of C# online submissions for Robot Return to Origin. Memory Usage:  25.8 MB , less than  5.55%  of C# online submissions for Robot Return to Origin. -------------------------------------------------------------------------------------------- 似乎不好,但簡單的寫法,歡迎大家流言討論,讓你我更好。

C# DB數字型態 對應

             [SQL] ------------------------------------ bigint   | -2^63~2^63-1)| 8位元組 ------------------------------------ int      |(-2^31~2^31-1)| 4位元組 ------------------------------------ smallint |(-2^15~2^15-1)| 2位元組 ------------------------------------ tinyint  |(0~255)       | 1位元組              [.netC#] ------------------------------------ Int64    | -2^63~2^63-1)| 8位元組 ------------------------------------ Int32    |(-2^31~2^31-1)| 4位元組 ------------------------------------ Integer  |(-2^31~2^31-1)| 4位元組 ------------------------------------ Int16    |(-2^15~2^15-1)| 2位元組 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓對應↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ [MS SQL] [C#] bit      <=> bool tinyint      <=> byte smal...

C# Stream 轉 Bytes

        #region - Stream 轉 Bytes -         /// <summary>         /// Stream 轉 Bytes         /// </summary>         /// <param name="stream"> Stream </param>         /// <returns> Bytes </returns>         public static byte [] StreamToBytes( Stream stream)         {             byte [] bytes = new byte [stream.Length];             stream.Read(bytes, 0, bytes.Length);             stream.Seek(0, SeekOrigin .Begin);             return...

MS SQL 目的:用浮點數加減時間換算

目的:用浮點數加減時間換算,例如:日期時間加上0.5小時 SELECT DATEADD(HOUR, 0.5, CAST('2015/01/01 08:00' AS DATETIME)) 執行結果還是一樣 2015/01/01 08:00 SELECT DATEADD(MINUTE, 0.5 * 60, CAST('2015/01/01 08:00' AS DATETIME)) 執行結果 2015/01/01 08:30 原因: DATEADD (datepart , number , date ) 參數:number,主要為int型別,0.5轉換int還是0 參考網址 https://msdn.microsoft.com/zh-tw/library/ms186819.aspx