OJ笔记】的更多相关文章

1.未考虑程序没有输出导致的格式错误: 原代码:(即使没有输出,ans集合元素为0,也输出了空格) set<int>::iterator it=ans.begin(); while(it!=ans.end()){ if(it!=ans.begin()) O(" "); O("%05d",*it); it++; } OL(""); AC代码: ){ set<int>::iterator it=ans.begin(); whi…
单点测试 PAT使用的就是单点测试(LeetCode应该也是单点测试).单点测试中系统会判断每组数据的输出结果是否正确,正确则通过测试并获得这则测试的分值.题目的总得分等于通过的数据的分值之和. 代码编写上单点测试只要求程序能够按照正常逻辑执行一遍. 多点测试 多点测试要求程序能够一次性运行所有数据,并且要求所有输出结果都完全正确才能AC,只要一组数据输出错误那么这题就只能0分.大部分OJ都是这种方式.只有这种方式才能严格考验写出的代码是否严谨.多点测试的程序需要能够运行所有数据,所以必须保证程…
================================== LeetCode的一些算法题,都是自己做的,欢迎提出改进~~ LeetCode:http://oj.leetcode.com ================================== <Reverse Words in a String>-20140328 Given an input string, reverse the string word by word. For example, Given s =…
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1 return [ [5,4,11,2],…
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11…
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more tha…
题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. Tags: Depth-first Search 分析 很基本的一道深度优…
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n) space is pretty straight forward. Could you devise a constan…
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right…
题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following is not: 1 / \ 2 2 \ \ 3 3 Note: B…