LeetCode解题
zuisixian
这个作者很懒,什么都没留下…
展开
-
326. Power of Three LeetCode解题报告
Given an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / recursion? 解法一:采用循环,O(lg(N))的速度class Solution {public: bool isPowe原创 2016-01-13 17:48:09 · 230 阅读 · 0 评论 -
236. Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and原创 2016-07-18 22:00:41 · 195 阅读 · 0 评论 -
1.Two Sum
1.Two SumGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example: Given nums =原创 2016-06-22 10:42:45 · 154 阅读 · 0 评论 -
337 leetcode House Robber III
欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦:Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键快捷键加粗 Ctrl + B 斜体 Ctrl + I 引用 Ctrl原创 2016-06-22 09:50:21 · 223 阅读 · 0 评论 -
24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may no原创 2016-07-05 11:30:13 · 196 阅读 · 0 评论 -
33. Search in Rotated Sorted Array
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).You are given a target value to search. If found in the array return its index原创 2016-07-26 19:21:28 · 175 阅读 · 0 评论 -
Max Sum of Rectangle No Larger Than K
对于一维数组求最大的和并且不大于K对于二维数组,转化为一维的迭代代码:class Solution {public: int maxSumSubmatrix(vector<vector<int>>& matrix, int k) { if (matrix.empty()) return 0; int row = matrix.si原创 2016-07-22 15:23:10 · 268 阅读 · 0 评论 -
119. Pascal's Triangle II
Given an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1].这就是杨辉三角class Solution {public: vector<int> getRow(int rowIndex) { vector<int> row(原创 2016-07-11 09:50:36 · 162 阅读 · 0 评论 -
237. Delete Node in a Linked List
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 is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, t原创 2016-04-07 11:11:09 · 177 阅读 · 0 评论 -
50.Pow(x,n)
求x的幂次方Implement pow(x, n).二分法注意-n 转化为n的时候溢出,需要处理一下class Solution {//超时用不了public:double myPow(double x, int n) { if(n==0) return 1; double t = myPow(x,n/2); if(n%2) return n<0 ? 1/x*t*t原创 2016-07-22 09:57:51 · 227 阅读 · 0 评论