
水题
文章平均质量分 60
markpen
这个作者很懒,什么都没留下…
展开
-
大战临近,先刷水题涨点自信!
pratiseEasy Game#include #include #include #include using namespace std;int main(){ int n,cas=0; cin>>n; string s; while(n--) { cas++; cin>>s; if原创 2014-06-28 23:19:56 · 525 阅读 · 0 评论 -
Leetcode Wiggle Sort II
leetcode 324 wiggle sort II原创 2016-07-29 21:35:02 · 233 阅读 · 0 评论 -
Leetcode Kth Largest Element in an Array
Leetcode 215 Kth Largest Element in an Array原创 2016-07-29 21:42:50 · 185 阅读 · 0 评论 -
Leetcode Counting Bits
Leetcode 338 Counting Bits原创 2016-07-29 21:59:17 · 201 阅读 · 0 评论 -
Leetcode Game of Life
Leetcode 289 Game of Life原创 2016-07-29 22:09:39 · 265 阅读 · 0 评论 -
Leetcode Set Matrix Zores
Leetcode 73 Set Matrix Zeros原创 2016-07-29 22:35:13 · 461 阅读 · 0 评论 -
Leetcode Find Peak Element
Leetcode162 Find Peak Element原创 2016-07-29 22:44:22 · 216 阅读 · 0 评论 -
Leetcode Pascal's Triangle II
Leetcode 119 Pascal's Triangle II原创 2016-07-30 13:49:29 · 264 阅读 · 0 评论 -
leetcode Number of Islands
Leetcode 200 Number of Islands原创 2016-08-10 17:58:00 · 275 阅读 · 0 评论 -
Leetcode H-Index
Leetcode 274 H-Index原创 2016-08-10 21:00:49 · 243 阅读 · 0 评论 -
Leetcode H-Index II
Leetcode 275 H-Index II原创 2016-08-10 21:26:50 · 196 阅读 · 0 评论 -
Leetcode Ransom Note
leetcode 383 Ransom Note原创 2016-08-12 22:30:38 · 796 阅读 · 0 评论 -
Leetcode Maximum Depth of Binary Tree
Leetcode 104 Maximum Depth of Binary Tree原创 2016-08-12 22:52:55 · 185 阅读 · 0 评论 -
Leetcode Invert Binary Tree
Leetcode 226 Invert Binary Tree原创 2016-08-12 23:01:52 · 187 阅读 · 0 评论 -
Leetcode Remove Duplicates from Sorted List
Leetcode 83 Remove Duplicates from Sorted List原创 2016-08-12 23:36:42 · 186 阅读 · 0 评论 -
Leetcode Maximum Subarray
Leetcode 53 Maximum Subarray原创 2016-08-13 11:35:10 · 209 阅读 · 0 评论 -
Leetcode Gray Code
Leetcode 89 Gray Code原创 2016-08-13 14:42:13 · 223 阅读 · 0 评论 -
Leetcode Balanced Binary Tree
题意:判断一棵树是否为平衡树。平衡树是指,各子树的高度之差不超过1。思路:计算各子树高度,并判断。class Solution {public: bool isBalanced(TreeNode* root) { if(!root) return true; bool bleft = false; bool bright = fal原创 2016-12-18 03:26:17 · 182 阅读 · 0 评论 -
Leetcode 2
listclass Solution {public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode *temp1 = l1; ListNode *temp2 = l2; ListNode *head = new ListNode(0); head->nex原创 2016-12-14 12:28:29 · 222 阅读 · 0 评论 -
Leetcode 17
题意:输入数字,找所以可能的字母组合。思路:DFS,到达叶结点输出。class Solution {public: vector b; vector re; vector letterCombinations(string digits) { string s = "abc"; b.push_back(s); s = "def";原创 2016-12-17 02:49:32 · 331 阅读 · 0 评论 -
Leetcode Valid Parentheses
题意:括号匹配。思路:堆栈。class Solution {public: bool isValid(string s) { stack mys; mys.push(s[0]); for(unsigned i = 1; i < s.length(); ++ i) { if(!mys.empty()) {原创 2016-12-17 03:32:06 · 233 阅读 · 0 评论 -
Leetcode Merge Two Sorted Lists
题意:合并两个排列好的队列。思路:列表的基本操作。class Solution {public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { ListNode *nextl1 = l1; ListNode *nextl2 = l2; ListNode原创 2016-12-17 03:49:19 · 194 阅读 · 0 评论 -
Leetcode Generate Parentheses
题意:写出所有合法的括号组合。思路:DFS。class Solution {public: vector re; vector generateParenthesis(int n) { string s = ""; dfs(s, n, n); return re; } int dfs(str原创 2016-12-17 07:09:45 · 229 阅读 · 0 评论 -
Leetcode Valid Sudoku
题意:检查数独是否合法,行列及九宫格的数字 不能重复。思路:暴力检查。class Solution {public: bool isValidSudoku(vector>& board) { bool isRepeat[10]; for(int i = 0; i < board.size(); ++ i) {原创 2016-12-17 08:18:26 · 197 阅读 · 0 评论 -
Leetcode Plus One
题意:整数加一。思路:模拟题。class Solution {public: vector plusOne(vector& digits) { vector re; int c = 0; for(int i = digits.size(); i > 0; -- i) { int d = digits[i -原创 2016-12-17 12:34:17 · 213 阅读 · 0 评论 -
Leetcode Same Tree
题意:判断两棵树是否相等。思路:DFS。class Solution {public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL && q == NULL) return true; if(p == NULL && q != NULL) return false;原创 2016-12-17 12:51:30 · 199 阅读 · 0 评论 -
Leetcode Minimum Path Sum
题意:只能向下或者向右,求路径最短。思路:简单DP。class Solution {public: int minPathSum(vector>& grid) { int m = grid.size(); int n = grid[0].size(); vector > dis = grid; fo原创 2016-12-17 14:47:32 · 206 阅读 · 0 评论 -
Leetcode Path Sum
题意:判断是否存在从根结点到叶结点,路上结点之和为所给的值的路径。思路:DFS。class Solution {public: bool hasPathSum(TreeNode* root, int sum) { if(root == NULL) return false; sum -= root->val; bo原创 2016-12-17 15:34:44 · 295 阅读 · 0 评论 -
Leetcode Submission Details
题意:找树最浅的深度。思路:DFS。class Solution {public: int minDepth(TreeNode* root) { if(root == NULL) return 0; if(root->left == NULL && root->right == NULL) return 1; int deeplef原创 2016-12-17 15:44:24 · 283 阅读 · 0 评论 -
Leetcode Basic Calculator
题意:编写一个基本的计算器,实现加减法操作。思路:用堆栈完成优先级操作。class Solution {public: int calculate(string s) { stack cal; for(int i = 0; i < s.length(); ++ i) { if(s[i] == ' ') continue;原创 2016-12-21 11:46:11 · 202 阅读 · 0 评论 -
Leetcode Insertion Sort List
题意:用链表实现插入排序。思路:简单模拟,注意处理链表的开头与结尾。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */cla原创 2016-12-22 01:46:12 · 204 阅读 · 0 评论 -
Leetcode Longest Increasing Path in a Matrix
题意:在矩阵中找最大递增路径。思路:DFS。向可能的四个方向搜索,将返回的最大值 + 1作为该结点的值。class Solution {public: vector > m; int xx,yy; vector > mmatrix; int longestIncreasingPath(vector>& matrix) { if(matrix原创 2016-12-22 09:22:15 · 263 阅读 · 0 评论 -
Leetcode Sort Characters By Frequency
题意:按字符出现频率降序输出字符。思路:用hash实现O(1)插入和查找。class Solution {public: string frequencySort(string s) { map m; for(int i = 0; i < s.length(); ++ i) { m[s[i]] ++; }原创 2016-12-22 11:28:41 · 266 阅读 · 0 评论 -
Leetcode Convert a Number to Hexadeci
题意:将一个数字转化成十六进制的形式。思路:简单模拟,注意负数符号位的处理。class Solution {public: string toHex(int num) { string re; if(num == 0) re += '0'; while(num) { int temp = num & 15;原创 2017-01-03 07:56:16 · 234 阅读 · 0 评论 -
Leetcode Best Time to Buy and Sell Stock II
题意:给出股票价格,可以多次买入、卖出,求利润的最大值。思路:只要股票价格上涨,就买入卖出。class Solution {public: int maxProfit(vector& prices) { if(prices.size() == 0) return 0; int maxbuy = 0; for(int原创 2016-12-23 00:26:48 · 162 阅读 · 0 评论 -
Leetcode Path Sum II
题意:找出各结点之和为给定值的所有路径。思路:DFS。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL)原创 2016-12-23 02:55:50 · 191 阅读 · 0 评论 -
Leetcode Divide Two Integers
题意:不使用除法操作完成整除运算。思路:采用和快速幂相类似的做法。注意边界处理。class Solution {public: int divide(int dividend, int divisor) { long df = 0; long tempd = dividend; long tempdi = divisor;原创 2016-12-23 03:54:51 · 169 阅读 · 0 评论 -
Leetcode Remove Duplicates from Sorted List II
题意:删除列表中重复的所有元素。思路:用hash表记录重复的元素,在链表中删除。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * };原创 2016-12-24 12:03:51 · 141 阅读 · 0 评论 -
Leetcode Battleships in a Board
题意:统计战舰的个数,其实就是统计相连的X的个数。思路:逐个检查,用DFS改相连的X。class Solution {public: vector > tempboard; int sizex, sizey; int countBattleships(vector>& board) { tempboard = board; size原创 2016-12-24 12:41:46 · 283 阅读 · 0 评论 -
Leetcode Arranging Coins
题意:求多少各连续自然数之和小于n。思路:求和公式。class Solution {public: int arrangeCoins(int n) { double tempn, tempx; tempn = n; tempx = sqrt(2 * tempn + 0.25) - 0.5; return floor(原创 2016-12-24 12:58:26 · 158 阅读 · 0 评论