https://helloacm.com/

转到作者网站

Given an array of integers A, return the largest integer that only occurs once. If no integer occurs once, return -1. Example 1: Input: Output: 8 Explanation: The maximum integer in the array is 9... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: We can use the following two algorithms:... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

Given preorder and inorder traversal of a tree, construct the binary tree. You may assume that duplicates do not exist in the tree. For example, given preorder = inorder = Return the following... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

You have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated through *, /, +, -, (, ) to get the value of 24. Example 1: Input: Output: True Explanation:... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it must... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

Given two sparse matrices A and B, return the result of AB. You may assume that A’s column number is equal to B’s row number. Example: Input: A = , ] B = , , ] Output: | 1 0 0... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

Given a list of dominoes, dominoes = is equivalent to dominoes = if and only if either (a==c and b==d), or (a==d and b==c) – that is, one domino can be rotated to be equal to another domino.... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

Given the root of a binary tree, find the maximum average value of any subtree of that tree. (A subtree of a tree is any node of that tree plus all its descendants. The average value of a tree is the... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

Design a Snake game that is played on a device with screen size = width x height. Play the game online if you are not familiar with the game. The snake is initially positioned at the top left corner... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

Design and implement a TwoSum class. It should support the following operations: add and find. add – Add the number to an internal data structure. find – Find if there exists any pair of... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

Given a table salary, such as the one below, that has m=male and f=female values. Swap all f and m values (i.e., change all f values to m and vice versa) with a single update statement and no... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

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 fence posts have the same color. Return the total... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certain color is different. You have to paint all the... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1. Sort the elements of arr1 such that the relative ordering of items in arr1 are the same... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

You are given coins of different denominations and a total amount of money. Write a function to compute the number of combinations that make up that amount. You may assume that you have infinite... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

Given a string S, remove the vowels ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’ from it, and return the new string. Example 1: Input:... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

On a staircase, the i-th step has some non-negative cost cost assigned (0 indexed). Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]

The Trie is common used data structure to speed up the word searching. The Trie is a structure to index the words character by character. Trie Definition in C++ Take a lowercase 26 letters for... [[ This is a content summary only. Visit my website for full links, other content, and more! ]]