原创 Largest Rectangle in Histogram -- 待看

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area

原创 兩個人拋硬幣來決定誰喫這個蘋果,先拋到正面者喫。問先拋者喫到蘋果的概率是多少?

  兩個人拋硬幣來決定誰喫這個蘋果,先拋到正面者喫。問先拋者喫到蘋果的概率是多少? 首先是拋的概率是1/2,這是個嵌套的無線循環的題目!想起當年考研電路題,很相似,經典。 要有總體思維,總體爲R ,分出一個,後續仍然爲無限長的電阻並聯仍

原创 Search Insert Position

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it wo

原创 Decode Ways

A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ...

原创 3Sum Closest

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Retu

原创 Best Time to Buy and Sell Stock III

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 t

原创 Distinct Subsequences

Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a

原创 4Sum

Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all un

原创 Jump Game

  Given an array of non-negative integers, you are initially positioned a

原创 Jump Game II

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element

原创 數字轉中文表示

此處表達式不超過萬。 注意的地方:1000,可以1001,即0的情況 (首,中,尾),11 ,12等,10 20 等情況! 此處未考慮負數情況,可以加以判斷,並且在開始加入負 #include <iostream> #include <

原创 Search a 2D Matrix

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

原创 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 t

原创 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 triplets i

原创 Search for a Range

Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's run