原创 華爲機試 - 字符串首字母轉換成大寫

#include <iostream> #include <cctype> #include <string> using namespace std; int main() { string str; getline(cin,st

原创 Leetcode - Tree /Dynamic Programming- Unique Binary Search

Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3,

原创 華爲機試 - 求字符串中最大最小值

輸入一串字符,只包含“0-10”和“,”找出其中最小的數字和最大的數字(可能不止一個),輸出最後剩餘數字個數。如 輸入 “3,3,4,5,6,7,7” #include <iostream> #include <map> #include

原创 Leetcode - Tree - Same Tree

Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if

原创 華爲機試 - 統計出現最多次數的數字

#include <iostream> #include <string> using namespace std; int main() { string str; getline(cin,str); int num[10]={

原创 Leetcode - Tree - 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 r

原创 Leetcode - Tree - Convert Sorted Array to Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST. /** * Definition for

原创 華爲機試 - 判斷if語句括號是否匹配

編程的時候,if條件裏面的“(”、“)”括號經常出現不匹配的情況導致編譯不過,請編寫程序檢測輸入一行if語句中的圓括號是否匹配正確。同時輸出語句中出現的左括號和右括號數量,如if((a==1)&&(b==1))是正確的,而if((a==

原创 Leetcode - Tree - Balanced Binary Tree

Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined a

原创 Leetcode - Tree - Binary Tree Traversal

1、Binary Tree Preorder Traversal  Given a binary tree, return the preorder traversal of its nodes' values. For examp

原创 華爲機試 - 計算字符串表達的運算

通過鍵盤輸入100以內正整數的加、減運算式,請編寫一個程序輸出運算結果字符串。 輸入字符串的格式爲:“操作數1 運算符 操作數2”,“操作數”與“運

原创 華爲機試 - 大數之和

求兩個長長整型的數據的和並輸出,例如輸入1233333333333333 。。。 3111111111111111111111111.。。。,則輸出。。。。 #include <iostream> #include <string>

原创 華爲機試 - 最小最大數之和

輸入整型數組求數組的最小數和最大數之和,例如輸入1,2,3,4則輸出爲5,當輸入只有一個數的時候,則最小數和最大數都是該數,例如只輸入1,則輸出爲2;另外數組的長度不超過50 #include <iostream> #include <

原创 華爲機試 - 字符串去重複字節/字符串去連續重複字節

通過鍵盤輸入一串小寫字母(a~z)組成的字符串。請編寫一個字符串過濾程序,若字符串中出現多個相同的字符,將非首次出現的字符過濾掉。 比如字符串“abacacde”過濾結果爲“abcde”。 要求實現函數: void stringFilte

原创 Leetcode - Tree - Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this bina