larray

package
v0.0.0-...-d229d73 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

https://leetcode.com/problems/add-to-array-form-of-integer/description/

For a non-negative integer X, the array-form of X is an array of its digits in left to right order. For example, if X = 1231, then the array form is [1,2,3,1].

Given the array-form A of a non-negative integer X, return the array-form of the integer X+K.

Example 1:

Input: A = [1,2,0,0], K = 34
Output: [1,2,3,4]
Explanation: 1200 + 34 = 1234

Example 2:

Input: A = [2,7,4], K = 181
Output: [4,5,5]
Explanation: 274 + 181 = 455

Example 3:

Input: A = [2,1,5], K = 806
Output: [1,0,2,1]
Explanation: 215 + 806 = 1021

Example 4:

Input: A = [9,9,9,9,9,9,9,9,9,9], K = 1
Output: [1,0,0,0,0,0,0,0,0,0,0]
Explanation: 9999999999 + 1 = 10000000000

Note:

	1 <= A.length <= 10000
	0 <= A[i] <= 9
	0 <= K <= 10000
	If A.length > 1, then A[0] != 0

 https://leetcode.com/problems/maximum-subarray/#/description

Find the contiguous subarray within an array (containing at least one number) which has the largest sum.

For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1] has the largest sum = 6.

More practice:

If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.

思路:直接开始累加,如果累加的和比当前元素还要小,ignore,开始下一轮查找,和保存在i-1的位置。这样,最后nums中保存了所有的局部最优解。

https://leetcode.com/problems/remove-duplicates-from-sorted-array/#/description

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.

Do not allocate extra space for another array, you must do this in place with constant memory.

For example, Given input array nums = [1,1,2],

Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively. It doesn't matter what you leave beyond the new length. 注意:nums需要处理一下,也就是不重复的元素要在前面,重复的需要挪到后面

https://leetcode.com/problems/sum-of-even-numbers-after-queries/description/

We have an array A of integers, and an array queries of queries.

For the i-th query val = queries[i][0], index = queries[i][1], we add val to A[index]. Then, the answer to the i-th query is the sum of the even values of A.

(Here, the given index = queries[i][1] is a 0-based index, and each query permanently modifies the array A.)

Return the answer to all queries. Your answer array should have answer[i] as the answer to the i-th query.

Example 1:

Input: A = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]]
Output: [8,6,2,4]
Explanation:
At the beginning, the array is [1,2,3,4].
After adding 1 to A[0], the array is [2,2,3,4], and the sum of even values is 2 + 2 + 4 = 8.
After adding -3 to A[1], the array is [2,-1,3,4], and the sum of even values is 2 + 4 = 6.
After adding -4 to A[0], the array is [-2,-1,3,4], and the sum of even values is -2 + 4 = 2.
After adding 2 to A[3], the array is [-2,-1,3,6], and the sum of even values is -2 + 6 = 4.

Note:

	1 <= A.length <= 10000
	-10000 <= A[i] <= 10000
	1 <= queries.length <= 10000
	-10000 <= queries[i][0] <= 10000
	0 <= queries[i][1] < A.length

 https://leetcode.com/problems/two-sum/#/description

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example: Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].

Index

Constants

View Source
const MaxInt = int(MaxUint >> 1)
View Source
const MaxUint = ^uint(0)
View Source
const MinInt = -MaxInt - 1

Variables

This section is empty.

Functions

func KSum

func KSum(nums []int, target, K int, result []int, results *[][]int)

Types

type Interval

type Interval struct {
	Start int
	End   int
}

type Intervals

type Intervals []Interval

func (Intervals) Len

func (intervals Intervals) Len() int

func (Intervals) Less

func (intervals Intervals) Less(i, j int) bool

func (Intervals) Swap

func (intervals Intervals) Swap(i, j int)

type Solution

type Solution struct {
	// contains filtered or unexported fields
}

func Constructor

func Constructor(nums []int) Solution

func (*Solution) Reset

func (this *Solution) Reset() []int

* Resets the array to its original configuration and return it.

func (*Solution) Shuffle

func (this *Solution) Shuffle() []int

* Returns a random shuffling of the array.

type SortPair

type SortPair [][]int

func (SortPair) Len

func (s SortPair) Len() int

func (SortPair) Less

func (s SortPair) Less(i, j int) bool

func (SortPair) Swap

func (s SortPair) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL