0%

Keyboard Row – LeetCode 500

Problem

Description

Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard like the image below.

Read more »

Next Greater Element I – LeetCode 496

Problem

Description

You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1’s elements in the corresponding places of nums2.

The Next Greater Number of a number x in nums1 is the first greater number to its right in nums2. If it does not exist, output -1 for this number.

Read more »

Construct the Rectangle – LeetCode 492

Problem

Description

For a web developer, it is very important to know how to design a web page’s size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements:

  • The area of the rectangular web page you designed must equal to the given target area.

  • The width W should not be larger than the length L, which means L >= W.

  • The difference between length L and width W should be as small as possible.

Read more »

Max Consecutive Ones – LeetCode 485

Problem

Description

Given a binary array, find the maximum number of consecutive 1s in this array.

Read more »

License Key Formatting – LeetCode 482

Problem

Description

GYou are given a license key represented as a string S which consists only alphanumeric character and dashes. The string is separated into N+1 groups by N dashes.

Given a number K, we would want to reformat the strings such that each group contains exactly K characters, except for the first group which could be shorter than K, but still must contain at least one character. Furthermore, there must be a dash inserted between two groups and all lowercase letters should be converted to uppercase.

Given a non-empty string S and a number K, format the string according to the rules described above.iven two binary strings, return their sum (also a binary string).

Read more »

Largest Palindrome Product – LeetCode 479

Problem

Description

Find the largest palindrome made from the product of two n-digit numbers.

Since the result could be very large, you should return the largest palindrome mod 1337.

Note:

The range of n is [1,8].

Read more »

Number Complement – LeetCode 476

Problem

Description

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.

Note:

  • The given integer is guaranteed to fit within the range of a 32-bit signed integer.
  • You could assume no leading zero bit in the integer’s binary representation.
Read more »

Heaters – LeetCode 475

Problem

Description

Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses.

Now, you are given positions of houses and heaters on a horizontal line, find out minimum radius of heaters so that all houses could be covered by those heaters.

So, your input will be the positions of houses and heaters seperately, and your expected output will be the minimum radius standard of heaters.

Note:

  • Numbers of houses and heaters you are given are non-negative and will not exceed 25000.
  • Positions of houses and heaters you are given are non-negative and will not exceed 10^9.
  • As long as a house is in the heaters’ warm radius range, it can be warmed.
  • All the heaters follow your radius standard and the warm radius will the same.
Read more »

Island Perimeter – LeetCode 463

Problem

Description

You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). The island doesn’t have “lakes” (water inside that isn’t connected to the water around the island). One cell is a square with side length 1. The grid is rectangular, width and height don’t exceed 100. Determine the perimeter of the island.

Read more »

Hamming Distance – LeetCode 461

Problem

Description

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

Given two integers x and y, calculate the Hamming distance.

Note:
$0 ≤ x, y < 2^{31}.$

Read more »