随笔分类 - Algorithm
classic algorithm, problem
摘要:class Solution {public: int searchInsert(int A[], int n, int target) { if (A == NULL || n target) { q = mi; } els...
阅读全文
摘要:class Solution {private: int getDirection(int A[], int idx, int target, bool isDefaultBack) { int r = A[idx] - target; if (r == 0) { ...
阅读全文
摘要:class Solution {public: vector grayCode(int n) { vector res; res.push_back(0); long pow2 = 1; for (int i=1; i grayCode...
阅读全文
摘要:class Solution {private: const static char* pattern[]; const static char* roman_digit[];public: string intToRoman(int num) { if (num ...
阅读全文
摘要:class Solution {public: char *strStr(char *haystack, char *needle) { if (haystack == NULL || needle == NULL) return NULL; int wpos[25...
阅读全文
摘要:class Solution {public: ListNode *swapPairs(ListNode *head) { ListNode *a = NULL; ListNode *b = NULL; ListNode *tail = NULL; ...
阅读全文
摘要:class Solution {public: void merge(int A[], int m, int B[], int n) { int mi = m + n - 1; int ai = m - 1; int bi = n - 1; ...
阅读全文
摘要:class Solution {private: static int compare(const Interval& a, const Interval& b) { return a.start merge(vector &intervals) { vector...
阅读全文
摘要:class Solution {public: ListNode *mergeKLists(vector &lists) { ListNode* merged = NULL; for (int i=0; ival val) { n...
阅读全文
摘要:Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"click to show corner cas...
阅读全文
摘要:class Solution {public: ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { ListNode* p = l1; ListNode* q = l2; ListNode* he...
阅读全文
摘要:class Solution {public: string getPermutation(int n, int k) { k--; if (n nums(n, 0); long seg = 1; for (int i=0; i= se...
阅读全文
摘要:class Solution {public: int climbStairs(int n) { if (n < 1) return 0; int a = 0; int b = 1; for (int i=0; i<n; i++) { ...
阅读全文
摘要:class Solution {public: ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) { ListNode* p = l1; ListNode* q = l2; ListNode* re...
阅读全文
摘要:const char* lookup[] = {" ", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxy...
阅读全文
摘要:Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word doe...
阅读全文
摘要:class Solution { public: vector > permuteUnique(vector &num) { vector > result; if (num.size() path; dfs(n...
阅读全文
摘要:class Solution { public: vector > generateMatrix(int n) { vector > matrix; if (n (n, 0)); }...
阅读全文
摘要:class Solution { public: vector spiralOrder(vector > &matrix) { vector ret; int cols = 0; ...
阅读全文
摘要:class Solution {public: int maxProfit(vector &prices) { int len = prices.size(); if (len maxv) { maxv = cur; ...
阅读全文

浙公网安备 33010602011771号