07 2014 档案
摘要:class Solution {public: ListNode *reverseKGroup(ListNode *head, int k) { if (k next = rhead; } last = rtail; } ...
阅读全文
摘要:Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 uni...
阅读全文
摘要:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and ...
阅读全文
摘要:struct mystat { int idx; int cnt[26]; mystat(int id = 0) {idx = id;}};bool cmp(const mystat &a, const mystat &b) { for (int i=0; i b.cnt[i...
阅读全文
摘要:class Solution {public: bool isMatch(const char *s, const char *p) { if (s == NULL || p == NULL) return false; int slen = 0; i...
阅读全文
摘要:最近一台服务器上的MySQL崩了,innodb单单靠.frm和.ibd好像恢复不过来,只能重装。但是重装也没让人省心,最好把/var/lib/mysql和/etc/mysql都删了,如果提示mysql-server-core要autoremove 的就在执行一次apt-get autoremove才...
阅读全文
摘要:小伙伴要在以前的服务器上装个代码版本控制的软件,要用到数据库,可是想来找去root密码还是忘了,其他已经安装的服务都是用的专用账户配置文件里要找不到root用户的密码。用以下方法将密码强制修改掉:1. 将mysql服务以安全模式方式运行,需要系统root权限sudo suservice mysql ...
阅读全文
摘要:class Solution {public: UndirectedGraphNode *cloneGraph(UndirectedGraphNode *node) { UndirectedGraphNode *clone = dfs(node); dfs_clea...
阅读全文
摘要:class Solution {public: int maxProfit(vector &prices) { int len = prices.size(); if (len i2r(len, 0); vector i2l(len, 0); ...
阅读全文
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express...
阅读全文
摘要:class Solution {public: int firstMissingPositive(int A[], int n) { if (A == NULL || n bits(len, false); for (int i=0; i n) continue;...
阅读全文
摘要:class Solution {private: const static char* pattern[]; const static char* roman[]; unordered_map a2i;public: int romanToInt(string s) { ...
阅读全文
摘要:class Solution {public: int trap(int A[], int n) { if (n peaks; vector peaks_tmp; int last_idx = 0; bool increasing = ...
阅读全文
摘要:class Solution {public: vector > subsetsWithDup(vector &S) { int len = S.size(); vector > res; vector subset; if (len ...
阅读全文
摘要:You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?class Solution {pub...
阅读全文
摘要:class Solution {public: bool isPalindrome(int x) { if (x =0; i--) { int a = n / tens; int b = n % 10; n = n...
阅读全文
摘要:class Solution {public: vector generateParenthesis(int n) { string str; vector res; dfs(n, 0, 0, str, res); return res;...
阅读全文
摘要:class Solution {public: int maxSubArray(int A[], int n) { int cur_sum = 0; int max_sum = INT_MIN; for (int i=0; i max_...
阅读全文
摘要:class Solution {public: void setZeroes(vector > &matrix) { int rows = matrix.size(); int cols = matrix[0].size(); bool...
阅读全文
摘要:class Solution {public: ListNode *removeNthFromEnd(ListNode *head, int n) { if (head == NULL) return NULL; ListNode* pre = NULL; ...
阅读全文
摘要:有时候需要一个独立的块设备,loop设备是个方便的选择,可通过如下方式创建dd if=/dev/zero of=./loopback_file bs=1M count=1000losetup /dev/loop0 ./loopback_file首先建立一个指定大小的文件作为实际存储的空间,然后将其与...
阅读全文
摘要:有些使用需要进行文件系统的大小调整,比如使用LVM,或者在loopback设备上建立文件系统等,但该文件系统不是根文件系统时可以通过一下步骤,简单的进行:e2fsck -f /dev/loop0resize2fs /dev/loop0 900M这里使用的块设备为/dev/loop0,调整大小为900...
阅读全文
摘要:class Solution {private: int queen_num; int total;public: int totalNQueens(int n) { queen_num = n; total = 0; vector h(n...
阅读全文
摘要:class Solution {public: void sortColors(int A[], int n) { int cnt[3] = {0}; for (int i = 0; i 0) start += cnt[i-1]; for (...
阅读全文
摘要:class Solution {private: vector sum; vector step; set can;public: int jump(int A[], int n) { step.clear(), sum.clear(), can.clear()...
阅读全文
摘要:class Solution {public: bool canJump(int A[], int n) { if (A == NULL || n sum(n, 0); int jump = A[n-1]; for (int i=n-...
阅读全文
摘要:class Solution {private: int queen_num; vector > res;public: vector > solveNQueens(int n) { res.clear(); queen_num = n; ...
阅读全文
摘要:class Solution {public: string countAndSay(int n) { vector num; num2digit(1, num); vector tmp; for (int i = 1; i &digit...
阅读全文
摘要:class Solution {public: TreeNode *buildTree(vector &inorder, vector &postorder) { int ilen = inorder.size(); int plen = postorder.siz...
阅读全文
摘要:class Solution {public: TreeNode *buildTree(vector &preorder, vector &inorder) { int plen = preorder.size(); int ilen = inorder.size(...
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *...
阅读全文
摘要:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(...
阅读全文
摘要:class Solution {public: vector restoreIpAddresses(string s) { vector ips; vector ip; dfs(s, 0, ip, ips); return ips; ...
阅读全文
摘要:class Solution {public: vector plusOne(vector &digits) { int carry = 1; int len = digits.size(); vector res; ...
阅读全文