1.Two Sum
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].
分析情境 : TwoSumInputNull、TwoSumNotFind、TwoSum
7.Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer.
Example 1: Input: 123 Output: 321 ~ Example 2: Input: -123 Output: -321 ~ Example 3: Input: 120 Output: 21
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows
分析情境 : ReverseInteger、ReverseIntegerOverPower
9.Palindrome Number
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example 1: Input: 121 Output: true
Example 2: Input: -121 Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Example 3: Input: 10 Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
分析情境 : PalindromeNumber、PalindromeNumberSingleInput
13.Roman to Integer
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
I 1 , V 5 , IV 4 , IX 9 , X 10 , X L 40 , L 50 , X C 90 , C 100 , C D 400 , D 500 , C M 900 , M 1000 For example, two is written as II in Roman numeral, just two one's added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, which is XX + V + II.
Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:
I can be placed before V (5) and X (10) to make 4 and 9. X can be placed before L (50) and C (100) to make 40 and 90. C can be placed before D (500) and M (1000) to make 400 and 900. Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.
Example 1: Input: "III" Output: 3 Example 2: Input: "IV" Output: 4 Example 3: Input: "IX" Output: 9
Example 4: Input: "LVIII" Output: 58 Explanation: L = 50, V= 5, III = 3.
Example 5: Input: "MCMXCIV" Output: 1994 Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
分析情境 : RomantoInteger、RomantoIntegerNotMap
14.Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "".
Example 1: Input: ["flower","flow","flight"] Output: "fl"
Example 2: Input: ["dog","racecar","car"] Output: ""
Explanation: There is no common prefix among the input strings. Note:All given inputs are in lowercase letters a-z.
分析情境 : LongestCommonPrefixInputNull、LongestCommonPrefixNotCommon、LongestCommonPrefix
20.Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid.
Example 1: Input: "()" Output: true Example 2: Input: "()[]{}" Output: true Example 3: Input: "(]" Output: false
Example 4: Input: "([)]" Output: false Example 5: Input: "{[]}" Output: true
分析情境 : ValidParenthesesInputNull、ValidParenthesesInputError、ValidParentheses
- Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
Example: Input: 1->2->4, 1->3->4 Output: 1->1->2->3->4->4
分析情境 : MergeTwoSortedListsInputNull、MergeTwoSortedLists
- Remove Duplicates from Sorted Array
Given a sorted array nums, 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 by modifying the input array in-place with O(1) extra memory.
Example 1 : Given 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 returned length.
Example 2 : Given nums = [0,0,1,1,1,2,2,3,3,4], Your function should return length = 5, with the first five elements of nums being modified to 0, 1, 2, 3, and 4 respectively. It doesn't matter what values are set beyond the returned length.
情境分析 : RemoveDuplicatesfromSortedArrayInputNull、RemoveDuplicatesfromSortedArray
- Remove Element
Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn't matter what you leave beyond the new length.
Example 1 : Given nums = [3,2,2,3], val = 3, Your function should return length = 2, with the first two elements of nums being 2. It doesn't matter what you leave beyond the returned length.
Example 2 : Given nums = [0,1,2,2,3,0,4,2], val = 2, Your function should return length = 5, with the first five elements of nums containing 0, 1, 3, 0, and 4. Note that the order of those five elements can be arbitrary. It doesn't matter what values are set beyond the returned length.
情境分析 : RemoveElementInputArrayNull、RemoveElementInputRemoveNull、RemoveElement
- Implement strStr()
Implement strStr().
Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Example 1 : Input: haystack = "hello", needle = "ll" Output: 2
Example 2 : Input: haystack = "aaaaa", needle = "bba" Output: -1
Clarification: What should we return when needle is an empty string? This is a great question to ask during an interview. For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C's strstr() and Java's indexOf().
情境分析 : ImplementstrStrInputNull、ImplementstrStrFindNull、ImplementstrStrSameNull、ImplementstrStr