ZMR小站

很高兴遇见你~


  • 首页

  • 标签

  • 分类

  • 归档

p20

发表于 2017-02-13 | 分类于 blog

LeetCode p20 Valid Parentheses 题解

1.题目:

Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid.

The brackets must close in the correct order, “()” and “()[]{}” are all valid but “(]” and “([)]” are not.

阅读全文 »

p14

发表于 2017-02-13 | 分类于 blog

LeetCode p14 Longest Common Prefix 题解

1.题目:

Write a function to find the longest common prefix string amongst an array of strings.

阅读全文 »

p9

发表于 2017-02-13 | 分类于 blog

LeetCode p9 Palindrome Number 题解

1.题目:

Determine whether an integer is a palindrome. Do this without extra space.

阅读全文 »

p7

发表于 2017-02-13 | 分类于 blog

LeetCode p7 Reverse Integer 题解

1.题目:

Reverse digits of an integer.

Example1: x = 123, return 321
Example2: x = -123, return -321

click to show spoilers.

Have you thought about this?
Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!

If the integer’s last digit is 0, what should the output be? ie, cases such as 10, 100.

Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer, then the reverse of 1000000003 overflows. How should you handle such cases?

For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

Note:
The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.

阅读全文 »

p447

发表于 2017-02-13 | 分类于 blog

LeetCode p447 Number of Boomerangs 题解

1.题目:

Given n points in the plane that are all pairwise distinct, a “boomerang” is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of the tuple matters).

Find the number of boomerangs. You may assume that n will be at most 500 and coordinates of points are all in the range [-10000, 10000] (inclusive).

Example:
Input:
[[0,0],[1,0],[2,0]]

Output:
2

Explanation:
The two boomerangs are [[1,0],[0,0],[2,0]] and [[1,0],[2,0],[0,0]]

阅读全文 »

p494

发表于 2017-02-13 | 分类于 blog

LeetCode p494 Target Sum 题解

1.题目:

You are given a list of non-negative integers, a1, a2, …, an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.

Find out how many ways to assign symbols to make sum of integers equal to target S.

Example 1:
Input: nums is [1, 1, 1, 1, 1], S is 3.
Output: 5
Explanation:

-1+1+1+1+1 = 3
+1-1+1+1+1 = 3
+1+1-1+1+1 = 3
+1+1+1-1+1 = 3
+1+1+1+1-1 = 3

There are 5 ways to assign symbols to make the sum of nums be target 3.
Note:
The length of the given array is positive and will not exceed 20.
The sum of elements in the given array will not exceed 1000.
Your output answer is guaranteed to be fitted in a 32-bit integer.

阅读全文 »

p28

发表于 2017-02-08 | 分类于 blog

LeetCode p28 Implement strStr() 题解

1.题目:

Implement strStr().

Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

阅读全文 »

1…789…33
ZhangMengRou

ZhangMengRou

ZMR小站

230 日志
4 分类
14 标签
© 2019 ZhangMengRou
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.4