Tag Archives: LeetCode

拿到Amazon面试,发一题3Sum

刚才收到了Amazon的面试邮件,第二个面试了,第一个没去…完了…题刷不完了…得突突刷了.

这个题最先想到的是用hashtable,然后写出来发现TLE过不了,最开始各种优化,虽然剪枝不少,但是根基太差,我甚至把内置的sorted()方法弃用改用快排.果然都是没效果.

后来改成了左右两边向中间移动的方式才AC Continue reading

这是来刷成就的么 Reverse Integer

这题目虽然下面提示你考虑溢出,但是没有溢出的test case,也没有给出溢出时的处理要求,所以虽然不知道他在说什么,但是感觉和做题没关系
Python的字符串那么好用…真不知道这题是想干啥

Reverse Integer

Reverse digits of an integer.

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

Continue reading

逗比题目ZigZag

这题没有啥难的,画个图想清楚直接坐标访问需要的字符就行了,稍微需要注意的就是最后边界要处理一下

ZigZag Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

P   A   H   N
A P L S I I G
Y   I   R

Continue reading

第四题啥都不想说…Add Two Numbers

我说这个题目感觉有问题…原来是自己没好好读题…
是说用两个链表表示两个非负数,每一位是逆向存储的…我就不说我理解成啥了…

Add Two Numbers

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8

Continue reading

终于刷第三题了Longest Substring Without Repeating Characters

Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “bbbbb” the longest substring is “b”, with the length of 1.

Continue reading