LeetCode (used to call i has 1337 code) is a social platform for preparing IT technical interviews. We strive to provide you with the best learning experience in preparing interviews for companies in the IT industry.
To be successful in a technical interview, we believe it is mainly repeating these three important steps:
Code. Read. Discuss.
We strive to provide you the LeetCode platform as the ultimate solution for preparing technical interviews.
1. Code -> Code solution using the Online Judge system.
2. Read -> Read high quality article featuring in-depth thought process. Also read other LeetCoders’ code.
3. Discuss -> Discuss your thoughts about the problem with other LeetCoders.
We hope that through our platform, you will grow into a LeetCoder. Not only will you be successful in all of your interviews, and most importantly, you will be a better coder in general !
--------------
All solutions are in Python!
S算法問題: Add Binary
問題描述:
Given two binary strings, return their sum (also a binary string).
For example,
a = "11"
b = "1"
Return "100".
S算法問題: 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
S算法問題: Anagrams
問題描述:
Given an array of strings, return all groups of strings that are anagrams.
Note: All inputs will be in lower-case.
算法問題推薦解法來了...
Sort the string to see if they're anagrams.
Solution 1 is simpler than 2.
解法(Python)
代碼: |
class Solution:
def anagrams(self, strs):
anagram_map, res = {}, []
for str in strs:
sorted_str = ("").join(sorted(str))
if sorted_str in anagram_map:
anagram_map[sorted_str].append(str)
else:
anagram_map[sorted_str] = [str]
for anagrams in anagram_map.values():
if len(anagrams) > 1:
res += anagrams
return res
# def anagrams(self, strs):
# """List comprehension may be more elegant but less readable here.
# """
# anagram_map = {}
# for str in strs:
# sorted_str = ("").join(sorted(str))
# if sorted_str in anagram_map:
# anagram_map[sorted_str].append(str)
# else:
# anagram_map[sorted_str] = [str]
# return [anagram for anagrams in anagram_map.values() if len(anagrams) > 1 for anagram in anagrams]
|
S算法問題: Balanced Binary Tree
問題描述:
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which
the depth of the two subtrees of every node never differ by more than 1.
S算法問題: Best Time to Buy and Sell Stock II
問題描述:
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as many transactions as you like
(ie, buy one and sell one share of the stock multiple times).
However, you may not engage in multiple transactions at the same time
(ie, you must sell the stock before you buy again).