Leetcode Diary

51.52. N-Queens(I II)

Leetcode Diary

The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle...

50. Pow(x, n)

Leetcode Diary

Implement pow(x, n), which calculates x raised to the power n (i.e. xn). Constraints: \[-100.0 < x < 100.0\] \[-2^{31} <= n <= 2^{31}-1\] \[-10^4 <= x^n <= 10...

49. Group Anagrams

Leetcode Diary

Given an array of strings strs, group the anagrams together. You can return the answer in any order. An anagrams is a word or phrase formed by rearranging the letters of a different word or p...

48. Rotate Image

Leetcode Diary

You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place, which means you have to modify the input 2D matrix d...

46.47. Permutations(I II)

Leetcode Diary

Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] Output: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ] Given a co...

45. Jump Game II

Leetcode Diary

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your ...

44. Wildcard Matching

Leetcode Diary

Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. '*' Matches any sequence of characters (includi...

43. Multiply Strings

Leetcode Diary

Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. Note: The length of both num1 and num2 is < 11...

42. Trapping Rain Water

Leetcode Diary

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. Example: Input: [0,1,0,2,1,0,1,3,2,1,2,1...

41. First Missing Positive

Leetcode Diary

Given an unsorted integer array, find the smallest missing positive integer. Your algorithm should run in O(n) time and uses constant extra space. Example: Input: [1,2,0] Output: 3 Input:...