- 博客(48)
- 收藏
- 关注
转载 LeetCode 617 Merge Two Binary Trees 合并二叉树
class Solution {public: TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) { if(t1 && t2) { TreeNode* root=new TreeNode(t1->val+t2->val); ro...
2018-10-24 10:20:44
220
原创 LeetCode 832 Flipping an Image 翻转图像
解法一:class Solution {public: vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) { int temp; for(int i=0;i<A.size();++i) { ...
2018-10-24 09:09:23
173
原创 LeetCode 657 Robot Return to Origin 机器人能否返回原点
解法一:class Solution {public: bool judgeCircle(string moves) { int l=0,r=0,u=0,d=0; for(int i=0;i<moves.size();++i) { if(moves[i]=='L') ++l;...
2018-10-23 08:52:02
338
原创 LeetCode 461 Hamming Distance 汉明距离
解法一:class Solution {public: int hammingDistance(int x, int y) { int z=x^y; int count=0; while(z) { ++count; z=z&(z-1); } ...
2018-10-23 08:40:25
170
原创 LeetCode 905 Sort Array By Parity 按奇偶排序数组
解法一:class Solution {public: vector<int> sortArrayByParity(vector<int>& A) { vector<int> ret; for(auto a:A) { if(a%2==0) ...
2018-10-22 16:19:06
132
转载 LeetCode 804 Unique Morse Code Words 唯一摩尔斯密码词
class Solution {public: int uniqueMorseRepresentations(vector<string>& words) { string codes[26] = {".-","-...","-.-.","-..",".","..-.","--.","...
2018-10-22 15:57:13
160
转载 LeetCode 709 To Lower Case 转换成小写字母
class Solution {public: string toLowerCase(string str) { for(auto &c:str) { if(c>='A' && c<='Z') c+=32; } return str;...
2018-10-21 11:59:04
133
转载 LeetCode 760 Find Anagram Mappings 查找字谜映射
Giventwo lists Aand B, and B is an anagram of A. B is an anagram of A means B is made by randomizing theorder of the elements in A.Wewant to find an index mapping P, from A to B. A mapping P[i] = ...
2018-10-21 11:34:40
180
原创 LeetCode 771 Jewels and Stones 宝石与石头
解法一:class Solution {public: int numJewelsInStones(string J, string S) { int count=0; for(int i=0;i<J.size();++i) for(int j=0;j<S.size();++j) { ...
2018-10-21 11:14:03
143
转载 LeetCode 110 Balanced Binary Tree 平衡二叉树
解法一:class Solution {public: bool isBalanced(TreeNode* root) { return balanceHeight(root)>=0; } int balanceHeight(TreeNode* root) { if(root==nullptr) ...
2018-10-20 11:10:17
135
转载 LeetCode 121 Best Time to Buy and Sell Stock II 买卖股票的最佳时机 II
class Solution {public: int maxProfit(vector<int>& prices) { int sum=0; for(int i=1;i<prices.size();i++) { int diff=prices[i]-prices[i-1]; ...
2018-10-19 09:21:47
121
转载 LeetCode 121 Best Time to Buy and Sell Stock 买卖股票的最佳时机
class Solution {public: int maxProfit(vector<int>& prices) { if(prices.size()<2) return 0; int profit=0; int cur_min=prices[0]; for(int i=...
2018-10-18 09:13:58
119
转载 LeetCode 169 Excel Sheet Column Number Excel表列序号
26进制转10进制,注意以'A'而不是0开头,因此要“+1”解法一:class Solution {public: int titleToNumber(string s) { int n = s.size(); int ret=0; for(int i = n-1; i >=0; --i) ret +=...
2018-10-17 09:09:34
152
转载 LeetCode 169 Majority Element 求众数
解法一:哈希表class Solution {public: int majorityElement(vector<int>& nums) { int n=nums.size(); unordered_map<int,int> count; for(int i=0;i<n;i++) ...
2018-10-16 09:24:05
143
原创 LeetCode 136 Single Number 只出现一次的数字
解法一:class Solution {public: int singleNumber(vector<int>& nums) { int x=0; for(auto i:nums) x^=i; return x; ...
2018-10-15 08:52:26
151
转载 HR面试问题集锦
请描述一件小时候您印象最深刻的事情 最大的挫折是什么,学到什么?求职者大可不必为自己的缺点遮遮掩掩,因为HR问这个问题的真实目的并不是想知道你有什么缺点,而是想借此问题考察你对自己的缺点有没有改正的态度。就好像HR问:你最大的失败经历是什么?他并不是想知道你是怎么失败的,而是想看你怎么对待失败的这件事。高考的失败,一方面原因是当时太看重高考,导致紧张,另一方面,因为过度的自信,对自己做过的题太...
2018-10-14 11:15:28
6936
转载 设计模式面试集锦
单例模式 在它的核心结构中包含一个被称为单例的特殊类,一个类只有一个实例,即一个类只有一个对象实例; 所有的单例模式都是使用静态方法进行创建的,所以单例对象在内存中静态共享区中存储; 单例模式分为饿汉式和懒汉式,懒汉式单例模式在类加载时不初始化,饿汉式单例模式,在类加载时就完成初始化,所以类加载较慢,但获取对象速度快。 手写线程安全的单例模式? 工厂模式 ...
2018-10-14 11:13:50
952
转载 数据库面试集锦
事务是什么 事务(txn)是一系列在共享数据库上执行的行为,以达到更高层次更复杂逻辑的功能。事务是DBMS中最基础的单位,事务不可分割。 ACID,是指在可靠数据库管理系统(DBMS)中,事务(transaction)所应该具有的四个特性:原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)、持久性(Durability)。 原子性...
2018-10-14 11:12:49
205
转载 数据结构面试集锦
数据结构 常用查找算法?具体实现 常用排序算法?具体实现,哪些是稳定的,时间复杂度、空间复杂度,快速排序非递归如何实现?快排的优势? 图的常用算法? 深度广度遍历; 广度优先遍历; 最短路径Floyed算法; 最短路径Dijktral算法; 最小生成树,Prime算法; 最小生成树Kuraul算法; 哈夫曼编码? 给定n个权值作为n个叶子结...
2018-10-14 11:11:57
689
转载 计算机网络面试集锦
物理层 数据链路层 网络层 路由器的功能? 路由选择与分组转发 ip报文如何从下向上交付 ip地址有什么用,ip地址和mac地址, 为什么需要IP地址 IP地址是在网络上分配给每台计算机或网络设备的32位数字标识。在Internet上,每台计算机或网络设备的IP地址是全世界唯一的。IP地址的格式是 xxx.x...
2018-10-14 11:10:57
954
转载 Linux面试集锦
Linux Inode节点 Linux操作系统引进了一个非常重要的概念inode,中文名为索引结点,引进索引接点是为了在物理内存上找到文件块,所以inode中包含文件的相关基本信息,比如文件位置、文件创建者、创建日期、文件大小等待,输入stat指令可以查看某个文件的inode信息; 硬盘格式化的时候,操作系统自动将硬盘分成两个区域,一个是数据区,一个是inode区,存放inod...
2018-10-14 11:09:01
513
转载 操作系统面试题集锦
操作系统特点 并发性、共享性、虚拟性、不确定性。 什么是进程 进程是指在系统中正在运行的一个应用程序,程序一旦运行就是进程; 进程可以认为是程序执行的一个实例,进程是系统进行资源分配的最小单位,且每个进程拥有独立的地址空间; 一个进程无法直接访问另一个进程的变量和数据结构,如果希望一个进程去访问另一个进程的资源,需要使用进程间的通信,比如:管道、消息...
2018-10-14 11:07:32
829
转载 C++面试题集锦
引用和指针的区别? 指针是一个实体,需要分配内存空间。引用只是变量的别名,不需要分配内存空间。 引用在定义的时候必须进行初始化,并且不能够改变。指针在定义的时候不一定要初始化,并且指向的空间可变。(注:不能有引用的值不能为NULL) 有多级指针,但是没有多级引用,只能有一级引用。 指针和引用的自增运算结果不一样。(指针是指向下一个空间,引用时引用的变量值加1) siz...
2018-10-14 11:03:30
881
转载 LeetCode Convert Sorted Array to Binary Search Tree 将有序数组转换为二叉搜索树
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...
2018-10-14 10:57:35
132
转载 LeetCode 107. Binary Tree Level Order Traversal II 二叉树的层次遍历 II
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */解法一...
2018-10-13 23:06:27
91
转载 LeetCode 100. Maximum Depth of Binary Tree 二叉树的最大深度
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...
2018-10-12 09:15:33
99
转载 LeetCode 100. Same Tree 相同的树
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...
2018-10-10 09:12:15
106
原创 LeetCode 88. Merge Sorted Array 合并两个有序数组
class Solution {public: void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) { for(auto it=nums2.begin();it!=nums2.end();it++) { int i=...
2018-10-09 09:10:53
120
原创 LeetCode 70. Remove Duplicates from Sorted List 删除排序链表中的重复元素
class Solution {public: ListNode* deleteDuplicates(ListNode* head) { if(head==nullptr) return nullptr; ListNode *p=head,*cur=head->next; while(cur) ...
2018-10-08 08:50:55
108
转载 LeetCode 70. Climbing Stairs 爬楼梯
解法一:class Solution {public: int climbStairs(int n) { int cur=1,prev=0; for(int i=1;i<=n;++i) { int tmp=cur; cur+=prev; prev=tmp; ...
2018-09-28 11:07:19
109
转载 LeetCode 69. Sqrt(x) x 的平方根
解法一:class Solution {public: int mySqrt(int x) { int left=1,right=x/2,last_mid; if(x<2) return x; while(left<=right) { const int mid...
2018-09-27 23:23:57
95
转载 LeetCode 67. Add Binary 二进制求和
解法一:class Solution {public: string addBinary(string a, string b) { string c; const size_t n=a.size()>b.size()?a.size():b.size(); reverse(a.begin(),a.end()); re...
2018-09-27 09:37:00
149
转载 LeetCode 66. Plus One 加一
class Solution {public: vector<int> plusOne(vector<int>& digits) { add(digits,1); return digits; } void add(vector<int> &digits,int c) {...
2018-09-26 09:37:00
97
转载 LeetCode 58. Length of Last Word 最后一个单词的长度
解法一:class Solution {public: int lengthOfLastWord(string s) { return LengthLastWorld(s.c_str()); } int LengthLastWorld(const char* s) { int length=0; while(*s...
2018-09-25 09:59:48
131
原创 LeetCode 53.Maximum Subarray 最大子序和
解法一:class Solution {public: int maxSubArray(vector<int>& nums) { int Max=nums[0]; int sum=0; for(int i=0;i<nums.size();i++) { sum=nums[...
2018-09-21 10:46:03
117
转载 LeetCode 38. Count and Say 报数
解法一:string countAndSay(int n) {if (n == 0) return "";string res = "1";while (--n) {string cur = "";for (int i = 0; i < res.size(); i++) {int count = 1;while ((i + 1 < res.size())...
2018-08-31 10:30:53
126
原创 LeetCode 35. Search Insert Position 搜索插入位置
解法一:class Solution {public: int searchInsert(vector<int>& nums, int target) { int i=0; for(;i<nums.size();i++) { if(target==nums[i]) ...
2018-08-30 09:35:51
105
原创 LeetCode 28. Implement strStr() 实现strStr()
class Solution {public: int strStr(string haystack, string needle) { if(needle=="") return 0; int j=0,n=-1; bool ISstr; for(int i=0;i<haystack.size(...
2018-08-29 09:23:24
104
原创 LeetCode 27. Remove Element 移除元素
class Solution {public: int removeElement(vector<int>& nums, int val) { int sum=0; for(auto it=nums.begin();it!=nums.end();it++) { if(*it==val) ...
2018-08-28 10:54:53
144
转载 32位float和double能表示的十进制有效数字
一个浮点数由三部分组成:符号位S、指数部分E(阶码)以及尾数部分M。 单精度浮点数(float)总共用32位来表示浮点数,其中尾数用23位存储,加上小数点前有一位隐藏的1(IEEE754规约数表示法),2^(23+1) = 16777216。因为 10^7 < 16777216 < 10^8,所以说单精度浮点数的有效位数是7位。考虑到第7位可能的四舍五入问题,所以单精度最少有6位有...
2018-08-28 10:00:58
8267
2
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人