代码改变世界

[LeetCode] 747. Largest Number At Least Twice of Others_Easy

2018-08-28 12:08 by Johnson_强生仔仔, 157 阅读, 0 推荐, 收藏, 编辑
摘要:In a given integer array nums, there is always exactly one largest element. Find whether the largest element in the array is at least twice as much as 阅读全文

[LeetCode] 840. Magic Squares In Grid_Easy

2018-08-28 12:02 by Johnson_强生仔仔, 323 阅读, 0 推荐, 收藏, 编辑
摘要:A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum. Gi 阅读全文

[LeetCode] 405. Convert a Number to Hexadecimal_Easy tag: Bit Manipulation

2018-08-28 08:27 by Johnson_强生仔仔, 162 阅读, 0 推荐, 收藏, 编辑
摘要:Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used. Note: Example 1: Example 2: 阅读全文

[LeetCode] 276. Paint Fence_Easy tag: Dynamic Programming

2018-08-28 08:14 by Johnson_强生仔仔, 235 阅读, 0 推荐, 收藏, 编辑
摘要:There is a fence with n posts, each post can be painted with one of the k colors. You have to paint all the posts such that no more than two adjacent 阅读全文

[LeetCode] 762. Prime Number of Set Bits in Binary Representation_Easy

2018-08-28 00:55 by Johnson_强生仔仔, 198 阅读, 0 推荐, 收藏, 编辑
摘要:Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation 阅读全文

[LeetCode] 693. Binary Number with Alternating Bits_Easy

2018-08-28 00:42 by Johnson_强生仔仔, 238 阅读, 0 推荐, 收藏, 编辑
摘要:Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. Example 1: Input: 5 O 阅读全文

[LeetCode] 434. Number of Segments in a String_Easy

2018-08-28 00:38 by Johnson_强生仔仔, 217 阅读, 0 推荐, 收藏, 编辑
摘要:Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters. Please note that the string 阅读全文

[LeetCode] 872. Leaf-Similar Trees_Easy tag: DFS

2018-08-28 00:01 by Johnson_强生仔仔, 215 阅读, 0 推荐, 收藏, 编辑
摘要:Consider all the leaves of a binary tree. From left to right order, the values of those leaves form a leaf value sequence. For example, in the given t 阅读全文

[LeetCode] 598. Range Addition II_Easy tag: Math

2018-08-27 23:48 by Johnson_强生仔仔, 186 阅读, 0 推荐, 收藏, 编辑
摘要:做个基本思路可以用 brute force, 但时间复杂度较高. 因为起始值都为0, 所以肯定是左上角的重合的最小的长方形就是结果, 所以我们求x, y 的最小值, 最后返回x*y. Code T: O(m*n) S: O(1) 阅读全文

[LeetCode] 661. Image Smoother_Easy

2018-08-27 12:07 by Johnson_强生仔仔, 157 阅读, 0 推荐, 收藏, 编辑
摘要:Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the ave 阅读全文
上一页 1 ··· 18 19 20 21 22 23 24 25 26 ··· 39 下一页