原创 【Leetcode】Two Sum II #Too easy, just review hashmap

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a spec

原创 【Leetcode】LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:

原创 【Leetcode】Sliding Window Maximum

Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very r

原创 【Leetcode】Rectangle Area && Classic Prob: Overlap Rectangle

Overlap Rectangle: 這道題的關鍵在於:不要去考慮overlap有幾種情況,雖然肯定能做出來,但是要考慮的情況太多了,不如就考慮一定不會overlap的情況。無非就是兩個rectangle x軸離的太遠或者y軸離得太遠

原创 【Leetcode】Binary Tree Level Order Traversal II

Very classic question and one of the hardest one I've met recently!!! The solution is also very clever and impressive!

原创 【Leetcode】Subsets

Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must be in non-desc

原创 【Leetcode】Search a 2D Matrix II

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:

原创 【Leetcode】Rotate Image

You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Coul

原创 【Leetcode】Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The lef

原创 【Leetcode】Longest palindrome substring

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

原创 【Leetcode】Maximum Size Subarray Sum Equals k

Example 1: Given nums = [1, -1, 5, -2, 3], k = 3, return 4. (because the subarray [1, -1, 5, -2] sums to 3 and is th

原创 【Leetcode】Kth Smallest Element in a BST

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note:  You may assu

原创 碰到一道經典的,Max Min Path

題目大概是這個意思:給定一個n*m的數組,找到每一條能從左上角探索到左下角的path,然後每一條path裏找到最小值,所有這些最小值合在一起,看最大值是哪個。 舉個例子: [8, 4, 7] [6, 5, 9] 有3條path: 8-4

原创 【Leetcode】Reverse LinkedList

太經典的題目了,我就不廢話了,只是爲了po這個我非常obsessed的方法: /** * Definition for singly-linked list. * public class ListNode { * int

原创 Reverse Half LinkedList

1-2-3-4-5-6 into 1-2-3-6-5-4 or 1-2-3-4-5 into 1-2-5-4-3 I took advantage of reversing a linkedlist. I provided main fu