leetcode 【LeetCode】198. House Robber 问题描述 You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is
leetcode 【LeetCode】190. Reverse Bits 问题描述 Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000). Follow up: If this function is
leetcode 【LeetCode】189. Rotate Array 问题描述 Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to
leetcode 【LeetCode】172. Factorial Trailing Zeroes 问题描述 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 阶乘末尾0的个数 分析 偶数乘以5末尾才会出现0,计算1-n出现含有5的个数即可。 代码 class Solution { public: int trailingZeroes(int
leetcode 【LeetCode】171. Excel Sheet Column Number 问题分析 Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C ->
leetcode 【LeetCode】169. Majority Element 问题描述 Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and
leetcode 【LeetCode】168. Excel Sheet Column Title 问题描述 Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA
leetcode 【LeetCode】165. Compare Version Numbers 问题描述 Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0. You may assume that the version strings are non-empty and contain only
leetcode 【LeetCode】160. Intersection of Two Linked Lists 问题描述 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: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b1
leetcode 【LeetCode】155. Min Stack 问题描述 Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. * push(x) -- Push element x onto stack. * pop() -- Removes the element on top of
leetcode 【LeetCode】141. Linked List Cycle 问题描述 Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 代码 class Solution { public: bool hasCycle(ListNode *head) { ListNode* p
leetcode 【LeetCode】136. Single Number 问题描述 Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra
leetcode 【LeetCode】11. Container With Most Water 问题描述 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,
leetcode 【LeetCode】125. Valid Palindrome 问题描述 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is
leetcode 【LeetCode】121. Best Time to Buy and Sell Stock 问题描述 Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie,
leetcode 【LeetCode】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]. Note: Could you optimize your algorithm to use only O(
leetcode 【LeetCode】118. Pascal's Triangle 问题描述 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 分析 设f(
leetcode 【LeetCode】112. Path Sum 问题描述 Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given
leetcode 【LeetCode】111. Minimum Depth of Binary Tree 问题描述 Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 二叉树最短路径问题。 问题分析
leetcode 【LeetCode】110. Balanced Binary Tree 问题描述 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
leetcode 【LeetCode】107. Binary Tree Level Order Traversal II 问题描述 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree [3,
leetcode 【LeetCode】104. 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 root node down to the farthest leaf node. 求树的深度 代码
leetcode 【LeetCode】102. Binary Tree Level Order Traversal 问题描述 Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree [3,9,20,null,null,15,
leetcode 【LeetCode】101. Symmetric Tree 问题描述 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1
C++ 【算法】检测数组里是否有两个数之和等于某个数 问题: 检测数组里是否有两个数之和等于某个数 解决方法一:先将数组排序,然后从两头开始遍历 数组排序后,从左端开始取最小值,从右端取最大值, 判断两者之和与目标的大小: 1. 等于时,输出两个数; 2. 大于时,右端移到第2个数,继续判断; 3. 小于时,左端移到第2个数,继续判断。 #include #include #include using namespace std; void fun1(int a[], int length, int