Online Judges

A collection of 18 posts

[LeetCode] 65. Valid Number

class Solution { public: bool isNumber(string s) { const char *p = s.c_str(), *q; // trim left while (std::isspace(*p)) ++p; if (*p == '+' || *p == '-') ++p; q = p; while (std::isdigit(

[LeetCode] 814. Binary Tree Pruning

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: TreeNode* pruneTree(TreeNode* root) { if (root->

[UVa] 1103 - Ancient Messages

Problem Link: UVa 1103 - Ancient Messages Hint DFS, 數洞洞 Solution C++ #include <iostream> #include <vector> #include <algorithm> static constexpr int MAX = 200 + 2; static const int

[UVa] 572 - Oil Deposits

Problem Link: UVa 572 - Oil Deposits Hint DFS Solution C++ #include <iostream> static const int DIRECTIONS[][2] = {{-1, -1}, {0, -1}, {1, -1}, {-1, 0}, /*{0, 0},*/ {1, 0}, {-1,

[UVa] 13148 - A Giveaway

題目 Link: UVa 13148 - A Giveaway Hint 這題真的是 Giveaway... Code C++ #include <iostream> #include <vector> #include <algorithm> constexpr const int MAX = 100000000; int main() { std::vector&

[UVa] 699 - The Falling leaves

Problem Link: UVa 699 - The Falling leabes hint preorder Code C++ with array #include <iostream> bool recursion(); static constexpr const int MAX = 100; // less stack consumption static int pile[MAX]