摘要: Implement int sqrt(int x).Compute and return the square root of x. 1 public static int Sqrt(int x) 2 { 3 if (x == 0) return 0; 4 5 ulong x2 = (ulong)x; 6 ulong l = 0; 7 ulong r = (ulong)x; 8 ulong mid; 9 10 whil... 阅读全文
posted @ 2012-10-17 23:52 ETCOW 阅读(484) 评论(0) 推荐(0) 编辑
摘要: Given an integer n, generate a square matrix filled with elements from 1 to n2(Square(n)) in spiral order.For example,Given n = 3,You should return the following matrix:[[ 1, 2, 3 ],[ 8, 9, 4 ],[ 7, 6, 5 ]] 1 public static List<List<int>> SparialMatrixII(int n) 2 { 3 List... 阅读全文
posted @ 2012-10-17 23:19 ETCOW 阅读(276) 评论(0) 推荐(0) 编辑
摘要: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[[ 1, 2, 3 ],[ 4, 5, 6 ],[ 7, 8, 9 ]]You should return [1,2,3,6,9,8,7,4,5]. 1 public static List<int> SprialMatrix(List<List<int>> matrix) 阅读全文
posted @ 2012-10-17 23:04 ETCOW 阅读(221) 评论(0) 推荐(0) 编辑
摘要: Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.Note:You are not suppose to use the 阅读全文
posted @ 2012-10-17 22:25 ETCOW 阅读(334) 评论(0) 推荐(0) 编辑
摘要: Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/http://www.cnblogs.com/c/", => "/c"Corner Cases:Did you consider the case where path = "/../"?In this case, you should return &quo 阅读全文
posted @ 2012-10-17 22:03 ETCOW 阅读(286) 评论(0) 推荐(0) 编辑
摘要: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 1 public static void SetMatrixZeros(List<List<int>> matrix) 2 { 3 bool col0 = false; 4 for (int i = 0; i < matrix.Count; i++) 5 { 6 for (i... 阅读全文
posted @ 2012-10-17 00:57 ETCOW 阅读(292) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here are few examples.[1,3,5,6], 5 → 2[1,3,5,6], 2 → 1[1,3,5,6], 7 → 4[1,3,5,6], 0 → 0 1 public ... 阅读全文
posted @ 2012-10-17 00:08 ETCOW 阅读(272) 评论(0) 推荐(0) 编辑