原创 Two Sum

Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may a

原创 Add Two Numbers

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each

原创 Longest Palindromic Substring

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

原创 Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", t

原创 14. Longest Common Prefix

題目:Write a function to find the longest common prefix string amongst an array of strings. 思路:找出最小長度的字符串,逐個子集判斷,判斷時可以使用s

原创 Leetcode 11. Container With Most Water

題目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical l

原创 Leetcode 19. Remove Nth Node From End of List

題目: Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked

原创 98. Validate Binary Search Tree

題目:判斷是不是搜索二叉樹 思路:1.中序遍歷的序列是嚴格遞增的。     2.節點的左子樹上的值均小於該節點的值,右子樹的值均大於該節點的值。 1. class TreeNode(object):     def __init__(s

原创 Leetcode 15. 3Sum

題目:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triple

原创 leetcode 66. Plus One

題目: Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.

原创 leetcode 69. Sqrt(x)

題目:求x的平方根 思路:牛頓法,https://en.wikipedia.org/wiki/Newton%27s_method class Solution(object):     def mySqrt(self, x):      

原创 leetcode 84. Largest Rectangle in Histogram

題目: Given n non-negative integers representing the histogram's bar height where the width of each bar

原创 Leetcode 22. Generate Parentheses

題目: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For exam

原创 Leetcode 8. String to Integer (atoi)

題目:Implement atoi to convert a string to an integer. 思路:編寫相應規則即可. import ctypes class Solution(object):     def myAto

原创 LeetCode 79. Word Search

題目: Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of seq