297. 二叉树的序列化与反序列化 序列化是将一个数据结构或者对象转换为连续的比特位的操作,进而可以将转换后的数据存储在一个文件或者内存中,同时也可以通过网络传输到另一个计算机环境,采取相反方式重构得到原数据。请设计一个算法来实现二叉树的序列化与反序列化。这里不限定你的序列 / 反序列化算法执行逻辑,你只需要保证一个二叉树可以被序列化为一个字符串并且将这个字符串反序列化为原始的树结构。示例:你可以将以下二叉树: 1 / \ 2 3 / \ 4 5序列化为 "[1,2,3,null,...
572. 另一个树的子树 给定两个非空二叉树 s 和 t,检验 s 中是否包含和 t 具有相同结构和节点值的子树。s 的一个子树包括 s 的一个节点和这个节点的所有子孙。s 也可以看做它自身的一棵子树。示例 1:给定的树 s: 3 / \ 4 5 / \1 2给定的树 t: 4 / \1 2返回 true,因为 t 与 s 的一个子树拥有相同的结构...
Leetcode 42 接雨水 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况下,可以接 6 个单位的雨水(蓝色部分表示雨水)。 感谢 Marcos 贡献此图。示例:输入: [0,1,0,2,1,0,1,3,2,1,2,1]输出: 6对于数组中的每个元素,我们找出下雨...
LeetCode 232. Implement Queue using Stacks Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the front element. em...
LeetCode 657.Robot Return to Origin There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves.The move sequence is repres...
LeetCode 219. Contains Duplicate II Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k....
LeetCode 206. Reverse Linked List Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLFollow up:A linked list can be reversed either iteratively or recursi...
LeetCode 203. Remove Linked List Elements Remove all elements from a linked list of integers that have value val.Example:Input: 1->2->6->3->4->5->6, val = 6Output: 1->2->3->4->5//java/** * Definition...
LeetCode 198. House Robber You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house...
LeetCode 1295. Find Numbers with Even Number of Digits Given an array nums of integers, return how many of them contain an even number of digits.Example 1:Input: nums = [12,345,2,6,7896]Output: 2Explanation: 12 contains 2 digits (even number of...
LeetCode 191. Number of 1 Bits Write a function that takes an unsigned integer and returnthe number of '1'bits it has (also known as the Hamming weight).Example 1:Input: 00000000000000000000000000001011Output: 3Explanat...
LeetCode 172. Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!.Example 1:Input: 3Output: 0Explanation:3! = 6, no trailing zero.Example 2:Input: 5Output: 1Explanation:5! = 120, one trai...
LeetCode 169. Majority Element Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element alwa...
LeetCode 167. Two Sum II - Input array is sorted Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers ...
LeetCode 155. Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Ge...
LeetCode 136. Single Number Given a non-emptyarray of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without us...
LeetCode 125. Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note:For the purpose of this problem, we define empty string as valid palindrome.Examp...
LeetCode 122. Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy on...
LeetCode 121. Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock),...
LeetCode 104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note:A leaf is a node with no childre...
LeetCode 88. Merge Sorted Array Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume tha...
LeetCode 53. Maximum Subarray Given an integer array nums, find the contiguous subarray(containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanati...
LeetCode 804. Unique Morse Code Words International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "b" maps to "-...", "c" maps to "-.-.", and so on.For c...
LeetCode 279. Perfect Squares Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.Example 1:Input: n = 12Output: 3 Explanation: 12 = 4 + 4 + 4.Example...
LeetCode 1021. Remove Outermost Parentheses A valid parentheses string is either empty (""), "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, "", "()", "(())()", and "(()...
LeetCode 27. Remove Element Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input arra...
LeetCode 709. To Lower Case Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.Example 1:Input: "Hello"Output: "hello"Example 2:Input: "here"Output: "here"...
LeetCode 938. Range Sum of BST Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive).The binary search tree is guaranteed to have unique values.Example 1:...
LeetCode 771. Jewels and Stones You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the sto...
LeetCode 26. Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modifyi...
LeetCode 21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: 1-...
LeetCode 20. Valid Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of b...
LeetCode 14. Longest Common Prefix Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".Example 1:Input: ["flower","flow","flight"]Output:...
LeetCode 13. Roman to Integer Roman numerals are represented by seven different symbols:I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...
Spring MVC 和 Spring 总结 1. 为什么使用Spring ? 1). 方便解耦,简化开发 通过Spring提供的IoC容器,可以将对象之间的依赖关系交由Spring进行控制,避免硬编码所造成的过度程序耦合。 2). AOP编程的支持 通过Spring提供的AOP功能,方便进行面向切面的编程,如性能监测、事务管理、日志记录等。 3). 声明式事务的支持...
C++产生随机数 函数一:int rand(void);从srand (seed)中指定的seed开始,返回一个 ( seed, RAND_MAX(0x7fff))间的随机整数。函数二:void srand(unsigned seed);参数seed是rand()的种子,用来初始化rand()的起始值。大致过程如下:rand()在每次被调用的时,它会查看:(1)如果用户在此之前调用过...
LeetCode 7. Reverse Integer Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dea...
LeetCode 3. Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters.Example 1:Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2:...
LeetCode 2. Add Two Numbers You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...
PAT-A 1036. Boys vs Girls (25) 1036. Boys vs Girls (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This tim...
PAT-A 1006. Sign In and Sign Out (25) 1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A...
PAT-A 1011. World Cup Betting (20) 1011. World Cup Betting (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue With...
PAT-B 1032. 挖掘机技术哪家强(20) 1032. 挖掘机技术哪家强(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 为了用事实说明挖掘机技术到底哪...
PAT-B 1028. 人口普查(20) 1028. 人口普查(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 某城镇进行人口普查,得到了全体居民的生...
PAT-B 1004. 成绩排名 (20) 1004. 成绩排名 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 读入n名学生的姓名、学号、成绩,分别...
PAT-B 1041. 考试座位号(15) 1041. 考试座位号(15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 每个PAT考生在参加考试时都会被分配...
PAT-A 1009. Product of Polynomials (25) 1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
PAT-A 1002. A+B for Polynomials (25) 1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Th...
PAT-B 1010. 一元多项式求导 (25) 1010. 一元多项式求导 (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 设计函数求一元多项式的导数。(注:xn(n为整数)的一阶导数为n*xn-1。)输入格式:以指数递降方...
PAT-A 1065. A+B and C (64bit) (20) 1065. A+B and C (64bit) (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming Gi...
PAT-A 1046. Shortest Distance (20) 1046. Shortest Distance (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...
博尔赫斯《你不是别人》 《你不是别人》博尔赫斯你怯懦地祈助的别人的著作救不了你你不是别人,此刻你正身处自己的脚步编织起的迷宫的中心之地耶稣或者苏格拉底所经历的磨难救不了你就连日暮时分在花园里圆寂的佛法无边的悉达多也于你无益你手写的文字,口出的言辞都像尘埃一般一文不值命运之神没有怜悯之心上帝的长夜没有尽期你的肉体只是时光,不停流逝的时光你不过是每一个孤独的瞬息 The writings left behind by tho...
PAT-A 1042. Shuffling Machine (20) 1042. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Shuf...
PAT-B 1018. 锤子剪刀布 (20) 1018. 锤子剪刀布 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 大家应该都会玩“锤子剪刀布”的游戏...
PAT-B 1012. 数字分类 (20) 1012. 数字分类 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一系列正整数,请按要求对数字进行...
PAT-B 1008. 数组元素循环右移问题 (20) 一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0 A1……AN-1)变换为(AN-M …… AN-1 A0 A1……AN-M-1)(最后M个数循环移至最前面的M个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?输入格式:每个输入包含一个测试用例,第1行输入N ( 1<=N&l...
PAT-B 1046. 划拳(15) 划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就赢了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。下面给出甲、乙两人的划拳记录,请你统计他们最后分别喝了多少杯酒。输入格式:输入第一行先给出一个正整数N(<=100),随后N行,每行给出一轮划拳的记录,格式...
PAT-B 1026. 程序运行时间(15) 要获得一个C语言程序的运行时间,常用的方法是调用头文件time.h,其中提供了clock()函数,可以捕捉从程序开始运行到clock()被调用时所耗费的时间。这个时间单位是clock tick,即“时钟打点”。同时还有一个常数CLK_TCK,给出了机器时钟每秒所走的时钟打点数。于是为了获得一个函数f的运行时间,我们只要在调用f之前先调用clock(),获得一个时钟打点数C1;在f执行完成后再调...
PAT-B 1016. 部分A+B (15) 1016. 部分A+B (15) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 正整数A的“DA(为1位整数)部分...
PAT-B 1011. A+B和C (15) 1011. A+B和C (15) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 HOU, Qiming 给定区间[-231, 231...
Maximum Subsequence Sum Maximum Subsequence SumGiven a sequence of KKK integers { N1N_1N1, N2N_2N2, ..., NKN_KNK }. A continuous subsequence is defined to be { NiN_iNi, Ni+1N_{i+1}Ni+1, ..., NjN_
最大子列和问题 最大子列和问题给定KKK个整数组成的序列{N1N_1N1,N2N_2N2, ..., NKN_KNK },“连续子列”被定义为{ NiN_iNi,Ni+1N_{i+1}Ni+1, ..., NjN_jNj },其中 1≤i≤j≤K1 \le i \le j \le K1≤i≤j≤K。“最大子列和”则被定义为所有连续子列
clock()函数模板 clock(): 捕捉从程序开始运行到clock()被调用时所耗费的时间。这个时间单位是clock tick,即“时钟打点”。常数CLK_TCK: 机器时钟每秒所走的时钟打点数。#include #include clock_t start, stop;/* clock_t是clock()函数返回的变量类型 */double duration;/* 记录被测函数运行时间,以秒为
PAT (Basic Level) Practise 1003. 我要通过! 1003. 我要通过!(20)时间限制 400 ms内存限制 65536 kB代码长度限制 8000 B判题程序 Standard 作者 CHEN, Yue“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于PAT的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正
POJ 2371 Questions and answers Questions and answersTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 11144 Accepted: 5922DescriptionThe database of the Pentagon contains a top-secret inf
CodeForces 445A DZY Loves Chessboard A. DZY Loves Chessboardtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDZY loves chessboard, and he enjoys playing wi
CodeForces 495A Digital Counter A. Digital Countertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMalek lives in an apartment block with 100 floors n
CodeForces 514B Han Solo and Lazer Gun B. Han Solo and Lazer Guntime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n Imperial stormtroopers on the fi
CodeForces 427B Prison Transfer B. Prison Transfertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe prison of your city has n prisoners. As the pri
CodeForces 387A George and Sleep A. George and Sleeptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGeorge woke up and saw the current time s on the d
CodeForces 617B Chocolate B. Chocolatetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob loves everything sweet. His favorite chocol
CodeForces 559A Gerald's Hexagon A. Gerald's Hexagontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGerald got a very curious hexagon for h
CodeForces 592B The Monster and the Squirrel B. The Monster and the Squirreltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAri the monster always wakes up very e
CodeForces 508A Pasha and Pixels A. Pasha and Pixelstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPasha loves his phone and also putting his hair u
CodeForces 233A Perfect Permutation A. Perfect Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA permutation is a sequence of integersp1, p
CodeForces 439B Devu, the Dumb Guy B. Devu, the Dumb Guytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDevu is a dumb guy, his learning curve is very s
CodeForces 599A Patrick and Shopping A. Patrick and Shoppingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday Patrick waits for a visit from his frien
CodeForces 200B Drinks B. Drinkstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Vasya loves orange juice very much. That's why any f
CodeForces 459B Pashmak and Flowers B. Pashmak and Flowerstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPashmak decided to give Parmida a pair of flowe
CodeForces 560A Currency System in Geraldion A. Currency System in Geraldiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA magic island Geraldion, where Geral
CodeForces 507A Amr and Music A. Amr and Musictime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAmr is a young coder who likes music a lot. He always
HDU 5479 Scaena Felix Scaena FelixTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 759 Accepted Submission(s): 321Problem DescriptionGiven a parenth
HDU 5494 Card Game Card GameTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 762 Accepted Submission(s): 476Problem DescriptionSoda and Beta are
HDU 5640 King's Cake King's CakeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 233 Accepted Submission(s): 190Problem DescriptionIt is the king's b
PAT (Basic Level) Practise 1002. 写出这个数 1002. 写出这个数 (20)时间限制 400 ms内存限制 65536 kB代码长度限制 8000 B判题程序 Standard 作者 CHEN, Yue读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保
PAT (Basic Level) Practise 1001. 害死人不偿命的(3n+1)猜想 1001. 害死人不偿命的(3n+1)猜想 (15)时间限制 400 ms内存限制 65536 kB代码长度限制 8000 B判题程序 Standard 作者 CHEN, Yue卡拉兹(Callatz)猜想:对任何一个自然数n,如果它是偶数,那么把它砍掉一半;如果它是奇数,那么把(3n+1)
CodeForces 31B Sysadmin Bob B. Sysadmin Bobtime limit per test0.5 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEmail address in Berland is a string of the form A@B
vector<string>字符串容器介绍 #include#includeusing namespace std;int main(){ vectorvec;//定义个一个字符串容器 vectorhi; string str; str="abc"; vec.push_back(str);//把字符串str压进容器 vec.push_back("def");//把字
CodeForces 132A Turing Tape #include#include#include#include#includeusing namespace std;char c[1200];int i,j,k,l,n,m,x,y,lans;int main(){ gets(c+1); n=strlen(c+1); lans=0; for(i=1;i<=n;i++){ x=c[i]; y=0; for(
CodeForces 44B Cola B. Colatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTo celebrate the opening of the Winter Computer School the or
CodeForces 38B Chess B. Chesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo chess pieces, a rook and a knight, stand on a standard c
CodeForces 56B Spoilt Permutation B. Spoilt Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya collects coins: he has exactly one coin f
CodeForces 47B Coins B. Coinstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Vasya came across three Berland coins. They didn't h
CodeForces 46B T-shirts from Sponsor B. T-shirts from Sponsortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day a well-known sponsor of a well-known
CodeForces 50B Choosing Symbol Pairs B. Choosing Symbol Pairstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a given string S consisting ofN s
HDU 5630 Rikka with Chess Rikka with ChessTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 41 Accepted Submission(s): 37Problem DescriptionYuta gives Rikk
CodeForces 628A Tennis Tournament A. Tennis Tournamenttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA tennis tournament with n participants is runnin
CodeForces 43B Letter B. Lettertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya decided to write an anonymous letter cutting the lett