Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the itinerary must begin with JFK.
Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome.
Given 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.
Problem Given a time in AM/PM format, convert it to military (24-hour) time. Input Format A single string containing a time in 12-hour clock format. Output Format Convert and print the given time in 24-hour format. Sample Input {代码...} Sample Output {代码...} Solution 1. using char[] {代码...} ...
Your teacher has given you the task of drawing a staircase structure. Being an expert programmer, you decided to make a program to draw it for you instead. Given the required height, can you print a staircase as shown in the example?
Given an array of integers, calculate which fraction of its elements are positive, which fraction of its elements are negative, and which fraction of its elements are zeroes, respectively. Print the decimal value of each fraction on a new line.
The first line contains an integer, N, denoting the size of the array. The second line contains N space-separated integers representing the array's elements.
三道基本相同的题目,都可以用位操作、递归和迭代来做。 Power of Two 1. Bit Manipulation -- 2 ms beats 21.88% {代码...} 2. Iteration -- 2 ms beats 21.88% {代码...} Power of Three 1. Recursion -- 20 ms beats 24% {代码...} 2. Iteration -- 15-17 ms beats 72.54%-91.74% {代码...} Power of Four Bit Manipu...
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.
Problem Given a list of integers, which denote a permutation. Find the previous permutation in ascending order. Notice The list may contains duplicate integers. Example For [1,3,2,3], the previous permutation is [1,2,3,3] For [1,2,3,4], the previous permutation is [4,3,2,1] Note Solution {代码...}
Problem Find the kth smallest number in at row and column sorted matrix. Example Given k = 4 and a matrix: {代码...} return 5 Challenge O(k log n), n is the maximal number in width and height. Note Solution I. Muggle (95% ac, last case exceeded time limit) {代码...} II. 堆排序 {代码...}
'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).