`
cozilla
  • 浏览: 92070 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论
文章列表
    class Solution { public: bool isMatch(const char *s, const char *p) { int ls = strlen(s); int lp = strlen(p); if (lp == 0) { if (ls != 0) return false; else return true; } if (lp >= 2 && p[1] == '*') { ...
    class Solution { public: vector<vector<int> > fourSum(vector<int> &num, int target) { sort(num.begin(),num.end()); vector<vector<int> > res; int* a = &num[0]; int len = num.size(); for (int i = 0; i ...
Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. Note:Given n will always be valid.Try to do ...
  Given a string containing just the characters '(', ')', '{', '}', '[' and 
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: "((()))", "(()())", "(())()", "()(())", "()()()" class Solution { public: vector<string&g ...
  class Solution { public: ListNode *swapPairs(ListNode *head) { if (head == NULL || head->next == NULL) return head; ListNode* newhead = head->next; ListNode* prev = NULL, *cur1 = head, *cur2 = head->next;; prev = cur1; cur1->next = cu ...
Spiral Matrix II Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example,Given n = 3, You should return the following matrix: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ] class Solution { public: vector<vector<int> > gen ...
      /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *rotateRight(ListNode *head, int k) { ListNode* tail = NULL; int l ...
      class Solution { public: int uniquePaths(int m, int n) { int dp[m+1][n+1]; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (i > 0) dp[i][j] += dp[i-1][j]; ...
刷题,练习手感!   /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { if (l1 == NULL) return l2 ...
Add Binary Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". class Solution { public: string addBinary(string a, string b) { int la = a.size(), lb = b.size(); int len = max(la, lb) + 2; ...
Search in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in the array return its index, otherwise return -1. You may assume no duplicate exists in ...
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / ...
Given a number represented as an array of digits, plus one to the number. 水题,练手感。 class Solution { public: vector<int> plusOne(vector<int> &digits) { int *a = new int[digits.size()+1]; memset(a, 0, digits.size()+1); int ret = 1, cur = 0; fo ...
Implement int sqrt(int x). Compute and return the square root of x.       class Solution { public: int sqrt(int x) { int l = 0, r = 46340; if (r*r <= x) return r; while (l < r) { if (r - l < 2) { if (r*r == x) return r; ...
Global site tag (gtag.js) - Google Analytics