![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 59
chendian920311
这个作者很懒,什么都没留下…
展开
-
leetcode 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 ext原创 2016-08-02 17:04:37 · 265 阅读 · 0 评论 -
leetcode Counting Bits
Counting BitsGiven a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Ex原创 2016-08-01 16:40:38 · 246 阅读 · 0 评论 -
leetcode Revert Binary Tree
homebrew的作者面试google,面试官要求他手写一个反转一个二叉树的功能。最后却没写出来,于是有了下面的新闻:Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off.原创 2016-08-02 17:38:57 · 280 阅读 · 0 评论 -
leetcode 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.统计二叉树的最大深度,分为BFS,和DFS原创 2016-08-02 17:27:22 · 228 阅读 · 0 评论 -
leetcode Add digits
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原创 2016-08-02 17:11:20 · 216 阅读 · 0 评论 -
Leetcode Sum of Two Intergers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.思路:1.两数相与,得到进位情况.2.两数异或,得到和。(without carray)利用这两条原创 2016-08-02 16:52:13 · 349 阅读 · 0 评论 -
leetcode Nim Game
292.Nim GameYou are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last原创 2016-08-01 17:05:10 · 254 阅读 · 0 评论 -
Leetcode Reverse String
LeetCode 344Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".思路:两根指针,分别指向字符串首尾。互相交换所指向的数值。当两根指针相遇时,即可遍历完毕。time原创 2016-08-01 16:06:05 · 230 阅读 · 0 评论 -
leetcode 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 the majority element原创 2016-08-04 16:35:15 · 269 阅读 · 0 评论 -
leetcode Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, ret原创 2016-08-04 16:28:05 · 240 阅读 · 0 评论 -
leetcode Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.用一个26位长度的桶原创 2016-08-04 16:18:40 · 243 阅读 · 0 评论 -
leetcode Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 思路,就是26进原创 2016-08-04 16:15:45 · 231 阅读 · 0 评论 -
leetcode Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number原创 2016-08-03 17:50:09 · 236 阅读 · 0 评论 -
leetcode Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.思路:这原创 2016-08-03 17:37:06 · 189 阅读 · 0 评论 -
Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].思路,求两个数组的交集。很明显要用hashmap或者集合,字典的数据结构,因为他们的key都是唯原创 2016-08-03 17:24:47 · 219 阅读 · 0 评论 -
leetcode Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements ofnums except nums[i].Solve it without division and in O(原创 2016-08-03 17:20:28 · 456 阅读 · 0 评论 -
leetcode Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you原创 2016-08-03 17:11:20 · 208 阅读 · 0 评论 -
378. Kth Smallest Element in a Sorted Matrix
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, not原创 2016-09-14 16:48:26 · 362 阅读 · 0 评论