Leetcode Brush title - Replay this week

This week the topic Archive

  • 00007 integer reversal
  • 00028 implement strStr ()
  • 00027 Removes the element
  • 00387 unique string of first character
  • 00206 reverse list
  • 00160 intersection list
  • 00088 merge two ordered arrays
  • 00088 merge two ordered arrays
  • 00001 two numbers
  • 00167 two numbers and II - an ordered array of input

00007 integer reversal

Title Description

Gives a 32-bit signed integer, you need this integer number on each inverted.

Example 1:

输入: 123
输出: 321

Example 2:

输入: -123
输出: -321

Example 3:

输入: 120
输出: 21

Force deduction address

Report problem-solving

00028 implement strStr ()

Title Description

Achieve strStr () function. Given a string and a needle haystack string, a position of the needle to find the first occurrence of the string (starting from 0) in the haystack string. If not, it returns -1.

Example 1:

输入: haystack = "hello", needle = "ll"
输出: 2

Example 2:

输入: haystack = "aaaaa", needle = "bba"
输出: -1

Force deduction address

Report problem-solving

00027 Removes the element

Title Description

Given an array nums and a value val, you need to place the elements to remove all equal values ​​val, and returns the new length of the array after removal.

Do not use extra space for an array, you must modify the input array in place and completed under the conditions of use O (1) extra space.

Order of the elements may be changed. You do not need to consider beyond the elements of the new array length behind

Force deduction address

Report problem-solving

00387 unique string of first character

Title Description

Given a string, find its first non-repeating characters, and returns its index. If not, it returns -1.

Case:

s = "leetcode"
返回 0.

s = "loveleetcode",
返回 2.

Note : You can assume that the string contains only lowercase letters.

Force deduction address

Report problem-solving

00206 reverse list

Title Description

Reverse a singly linked list.

Example:

输入: 1->2->3->4->5->NULL
输出: 5->4->3->2->1->NULL

Force deduction address

Report problem-solving

00160 intersection list

Title Description

Write a program to find the starting node two single list intersect.

Force deduction address

Report problem-solving

00021 merge two ordered lists

Title Description

The two ordered lists into a new sorted list and return. The new list is by all nodes in a given mosaic composed of two lists.

Example:

输入:1->2->4, 1->3->4
输出:1->1->2->3->4->4

Force deduction address

Report problem-solving

00088 merge two ordered arrays

Title Description

Given two ordered arrays of integers and nums2 nums1, incorporated into the nums2 nums1 in an ordered array such as a num1.

Description:

  • And initializing the number of elements nums1 nums2 of m and n.
  • You can assume nums1 sufficient space (space equal to or greater than m + n) to save the elements of nums2.

Example:

输入:

nums1 = [1,2,3,0,0,0], m = 3
nums2 = [2,5,6],       n = 3

输出: [1,2,2,3,5,6]

Force deduction address

Report problem-solving

00001 two numbers

Title Description

Given an array of integers and a target value, and identify the array as the number two target values.

You can assume only one answer corresponding to each input, and the same element can not be reused.

Example:

给定 nums = [2, 7, 11, 15], target = 9

因为 nums[0] + nums[1] = 2 + 7 = 9, 所以返回 [0, 1]

Force deduction address

Report problem-solving

00167 two numbers and II - an ordered array of input

Title Description

It has been given a follow 升序排列ordered array to find the number of two numbers such that their sum is equal to the target sum.

Function should return the two index values index1and index2which index1must be less than index2.

Description:

  • Return values of the index ( index1and index2) is not zero.
  • You can assume that each input corresponding to only the only answer, but you can not reuse the same elements.

Example:

输入: numbers = [2, 7, 11, 15], target = 9
输出: [1,2]
解释: 2 与 7 之和等于目标数 9 。因此 index1 = 1, index2 = 2 。

Force deduction address

Report problem-solving



Author: Lin Yun Hee
link: https: //www.jianshu.com/p/91fab1ce1d86
Source: Jane books
are copyrighted by the author. Commercial reprint please contact the author authorized, non-commercial reprint please indicate the source.

Guess you like

Origin www.cnblogs.com/dennisit/p/12094695.html