上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 25 下一页
摘要: 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)spiral 总共转了几圈 2) 最后一圈的时候如果是“横”“竖”需要处理好边界class Solution {public: ve... 阅读全文
posted @ 2013-08-01 15:23 冰点猎手 阅读(209) 评论(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. 很挫的一个想法: 使用O(M+N)的spaceclass Solution {public: void setZeroes(vector > &matrix) { // Start typing your C/C++ solution below // DO NOT write int main() function int m = matrix.size()... 阅读全文
posted @ 2013-08-01 11:55 冰点猎手 阅读(251) 评论(0) 推荐(0)
摘要: You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?The rotation can be performed in layers, where you perform a cyclic swap on the edges oneach layer In the frst for loop, we rotate the frst layer (outermost edges) W 阅读全文
posted @ 2013-07-31 23:20 冰点猎手 阅读(485) 评论(0) 推荐(0)
摘要: Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions. class Solution {public: bool isValid(int* row, int curRow) { for(int i = 0; in = n; int *row = new int[n]; nqueue(row, 0); return res; }pri... 阅读全文
posted @ 2013-07-30 23:08 冰点猎手 阅读(176) 评论(0) 推荐(0)
摘要: The n-queens puzzle is the problem of placing n queens on an n�n chessboard such that no two queens attack each other. Given an integern, return all distinct solutions to then-queens puzzle.Each solution contains a distinct board configuration of then-queens' placement, where'Q'and'. 阅读全文
posted @ 2013-07-30 22:53 冰点猎手 阅读(354) 评论(0) 推荐(0)
摘要: Singleton 三要素:private 构造函数、 public 静态方法、 public 静态变量单实例模式的三种线程安全实现方式(C++)1 懒汉模式:即第一次调用该类实例的时候才产生一个新的该类实例,并在以后仅返回此实例。需要用锁,来保证其线程安全性:原因:多个线程可能进入判断是否已经存在实例的if语句,从而non thread safety.使用double-check来保证thread safety.但是如果处理大量数据时,该锁才成为严重的性能瓶颈。class Singleton{ private : static Singleton * m_instance... 阅读全文
posted @ 2013-07-30 09:56 冰点猎手 阅读(344) 评论(0) 推荐(0)
摘要: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement must be in-place, do not allocate extra memory.He 阅读全文
posted @ 2013-07-29 22:19 冰点猎手 阅读(471) 评论(0) 推荐(0)
摘要: Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Return 1 since the palindrome partitioning ["aa","b"] could be produced using 1 cut. 分 阅读全文
posted @ 2013-07-29 21:03 冰点猎手 阅读(162) 评论(0) 推荐(0)
摘要: Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","b"], ["a","a","b"] ] DFS 求解全解神器class Solution {public: bo 阅读全文
posted @ 2013-07-27 12:14 冰点猎手 阅读(166) 评论(0) 推荐(0)
摘要: Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, note the restriction of using extra space.You could also try reversing an integer. However, if you have solved 阅读全文
posted @ 2013-07-27 11:39 冰点猎手 阅读(225) 评论(0) 推荐(0)
上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 25 下一页