- 博客(16)
- 收藏
- 关注
原创 258 Add Digits - LeetCode
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on
2015-08-22 14:04:24 304
原创 Lowest Common Ancestor of a Binary Search Tree-leetcode
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw
2015-07-19 19:52:37 302
原创 Container With Most Water——LeetCode
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin
2015-04-13 15:16:13 243
原创 Balanced Binary Tree——LeetCode
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 diffe
2015-04-13 15:11:20 204
原创 Binary Tree Postorder Traversal—LeetCode
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].1、递归vector postor
2015-04-13 08:59:11 275
原创 Add Binary —LeetCode
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".string addBinary(string a, string b) { if(a.size()==0) return b;
2015-04-12 20:45:50 240
原创 Trapping Rain Water—LeetCode(2015/4/8腾讯基础研究线上笔试题)
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]
2015-04-12 20:16:59 435
原创 Sort Colors —LeetCode
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers
2015-04-11 21:35:37 385
原创 整数除法的取整方式
在二分查找中,我们常用到以下表现int low=x;int high=y;int mid=(low+high)/2;由于C++在处理整数除法的时候,是向零取整的,即:int a=(1+2)/2;//a=1int a=(-1-2)/2,//a=-1故low由此在有关 的二分查找实现中(类似:Find Peak Element—LeetCode第三种方式点击打开链接),
2015-04-11 20:28:01 2524 1
原创 Find Peak Element—LeetCode
A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, i
2015-04-11 18:48:22 340
原创 Find Minimum in Rotated Sorted Array—LeetCode
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate exists in
2015-04-11 16:39:01 193
原创 Convert Sorted Array to Binary Search Tree-LeetCode
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.递归建树:TreeNode *sortedArrayToBST(vector &num) { if(num.size()==0) return nullptr;
2015-04-11 16:04:01 265
原创 Remove Duplicates from Sorted List-LeetCode
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.1、每找到一个相同元素的节点则直接删除
2015-04-11 13:05:21 292
原创 Search Insert Position -LeetCode
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.
2015-04-10 21:29:32 253
原创 mysizeof-腾讯软件开发-移动端(2015.4.8)笔试题
题目:使用C语言实现sizeof()函数,用于测试该主机整型数位数(16/32/64);1、位运算(有符号整型中,所有位为1时,代表的数为-1)int mySizeOf(){ int a=0; int b=1; int count=0; while(a!=-1) { a=a^b; b=b<<1; count++; } return count;}2
2015-04-10 10:49:30 342
原创 199 Binary Tree Right Side View-LeetCode
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1
2015-04-10 09:53:42 232
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人