摘要:
https://oj.leetcode.com/problems/sudoku-solver/九宫格数独问题。一行上为1 2 3 到9一列上为1 2 3 到9每个小的3*3格子为 1 2 3 到9使用深搜递归实现:在技巧上,使用类的成员变量vector > board; 这样不用每层递归都传递这个棋...
阅读全文
posted @ 2014-07-31 20:59
qingcheng奕
阅读(153)
推荐(0)
编辑
摘要:
#include map dict;map是基于红黑树实现的,可以快速查找一个元素是否存在,是关系型容器,能够表达两个数据之间的映射关系。dict.insert(make_pair("abc",1));dict.count("mn"); 看看dict中含有 mn的个数,因为元素是唯一的,所以这个返回...
阅读全文
posted @ 2014-07-30 22:16
qingcheng奕
阅读(1646)
推荐(0)
编辑
摘要:
https://oj.leetcode.com/problems/substring-with-concatenation-of-all-words/找S中子串,每个元素都在T中出现了,且所有T中元素都在S子串中出现了class Solution {public: vector findSub...
阅读全文
posted @ 2014-07-30 21:48
qingcheng奕
阅读(152)
推荐(0)
编辑
摘要:
https://oj.leetcode.com/problems/n-queens-ii/N皇后问题,计算解的个数class Solution {public: int totalNQueens(int n) { if(n places(n,-1); ...
阅读全文
posted @ 2014-07-29 21:01
qingcheng奕
阅读(119)
推荐(0)
编辑
摘要:
https://oj.leetcode.com/problems/n-queens/n皇后问题,1皇后有1个解,4皇后2个解,8皇后也有解……每个皇后不能在同一行上,同一列上,以及同一条45度线上。可以把皇后所在位置用一维数组表示,比如 2 0 3 1,表示第0个皇后在第0行的第二个位置上……所以验...
阅读全文
posted @ 2014-07-29 20:55
qingcheng奕
阅读(112)
推荐(0)
编辑
摘要:
https://oj.leetcode.com/problems/multiply-strings/用字符串实现大数乘法,细节题,细节很多 class Solution {public: string multiply(string num1, string num2) { if...
阅读全文
posted @ 2014-07-29 19:03
qingcheng奕
阅读(142)
推荐(0)
编辑
摘要:
https://oj.leetcode.com/problems/lru-cache/涨姿势的一道题,相当于实现一种数据结构,实现最近最少使用数据结构。// 用来记录 前后节点都是什么 类似链表上的节点 struct DataNode{ int key, value; ...
阅读全文
posted @ 2014-07-29 11:29
qingcheng奕
阅读(149)
推荐(0)
编辑
摘要:
https://oj.leetcode.com/problems/maximal-rectangle/给一个二维矩阵,里面只有0 1,求一个最大的矩阵,里面的所有元素都是1.首先预处理: 0 1 1 1 0 1 1做一个二维数组,记录到目前为止本行上连续1的个数,为 0 1 2 3 0 1 2之后再...
阅读全文
posted @ 2014-07-29 10:05
qingcheng奕
阅读(162)
推荐(0)
编辑
摘要:
https://oj.leetcode.com/problems/maximum-subarray/给了一个数组一列数,求其中的连续子数组的最大和。O(n)复杂度class Solution {public: int maxSubArray(int A[], int n) { i...
阅读全文
posted @ 2014-07-28 17:09
qingcheng奕
阅读(105)
推荐(0)
编辑
摘要:
https://oj.leetcode.com/problems/merge-intervals/合并区间//排序sort(intervals.begin(),intervals.end(),CMPFUN);bool CMPFUN(Interval a, Interval b){ return...
阅读全文
posted @ 2014-07-27 16:23
qingcheng奕
阅读(118)
推荐(0)
编辑