07 2015 档案
摘要:Implement a basic calculator to evaluate a simple expression string.The expression string contains onlynon-negativeintegers,+,-,*,/operators and empty...
阅读全文
摘要:Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. Th...
阅读全文
摘要:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.题意: 实现除法,但不允许用乘、除、以及取模运算。思路: 一下一下减必然显得...
阅读全文
摘要:Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted in asc...
阅读全文
摘要:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ord...
阅读全文
摘要:Given an arraynums, there is a sliding window of sizekwhich is moving from the very left of the array to the very right. You can only see theknumbers ...
阅读全文
摘要:Given an array ofnintegers wheren> 1,nums, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexceptnums[i].Solv...
阅读全文
摘要:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is1 -> 2 -> 3 -> ...
阅读全文
摘要:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to thedefinition of LCA on Wikipedia: “The lowest ...
阅读全文
摘要:思路: 利用位运算C++: 1 #include 2 using namespace std; 3 4 int main() 5 { 6 int a = 11, b = 17; 7 int sum, carry; 8 do 9 {10 sum =...
阅读全文
摘要:思路: 利用二分查找,分别查找待统计数字的头和尾的下标,最后做差加一即为结果。C++: 1 #include 2 #include 3 using namespace std; 4 5 int GetFirstK(vector& nums, int startpos, int endpos,...
阅读全文
摘要:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ...
阅读全文
摘要:Given a singly linked list, determine if it is a palindrome.思路: 用快慢指针找到链表中点,反转后半部分链表,然后与前半部分进行匹配,随后将链表恢复原状(本题没有这个要求,具体情况具体对待)。C++: 1 /** 2 * Definit...
阅读全文
摘要:只包含因子2、3、5的数称作丑数。 1 #include 2 #include 3 using namespace std; 4 5 int GetUglyNumber(int n) 6 { 7 if(n UglyNum(n, 0);11 UglyNum[0] = 1;12 ...
阅读全文
摘要:输入一颗二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。C++: 1 #include 2 using namespace std; 3 4 struct TreeNode 5 { 6 int val; 7 TreeNode *left; 8 TreeNode *...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 void Merge(vector& nums, const int first, const int mid, const int last, vector&temp) 6 { 7 i...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 void quickSort(vector& nums, const int lpos, const int rpos) 6 { 7 if(lpos = key)16 ...
阅读全文
摘要:思路: 没啥好说的,BFS。C++: 1 #include 2 #include 3 using namespace std; 4 5 struct TreeNode { 6 int val; 7 TreeNode *left; 8 TreeNode *right; ...
阅读全文
摘要:思路: 不停地压栈,直到栈头元素与弹出序列的首元素相等则出栈,同时弹出序列后移;若不相等则一直保持压栈,直到压入所有元素后弹出序列仍不为空,则说明无法匹配。C++: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 bo...
阅读全文
摘要:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.题意: 一颗二叉搜索树中有2个结点的元素被误换了,要求恢复二叉搜索树的...
阅读全文
摘要:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a...
阅读全文
摘要:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callingnext()will return the next...
阅读全文
摘要:Given an integer, write a function to determine if it is a power of two.思路: 如果一个数是2的Power,那么该数的二进制串中只有一位为1,其余都为0。执行一次n & (n - 1)可消除最低位的一个1,若消除后为0,则说明...
阅读全文
摘要:Given a binary search tree, write a functionkthSmallestto find thekth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST's tota...
阅读全文
摘要:Given a range [m, n] where 0 >=1; 7 n>>=1; 8 offset++; 9 }10 return m> 110 n = n >> 111 ...
阅读全文
摘要:Given an integer array of sizen, find all elements that appear more than⌊ n/3 ⌋times. The algorithm should run in linear time and in O(1) space.思路: 【...
阅读全文
摘要:Given an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may assume that the arr...
阅读全文

浙公网安备 33010602011771号