顯示具有 [網站]leetcode 標籤的文章。 顯示所有文章
顯示具有 [網站]leetcode 標籤的文章。 顯示所有文章

2014年6月6日 星期五

leetcode 151 - Longest Palindromic Substring

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, and there exists one unique longest palindromic substring.

先解釋什麼叫 palindromic,中文翻譯大概是迴文
也就是說左邊讀過去跟右邊讀回來是一樣對稱的
各國都有這樣的惡搞文化

2014年5月28日 星期三

leetcode 151 - 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.

2014年5月27日 星期二

leetcode 151 - Two Sum

就不發解答了,畢竟對岸一堆神人早就把答案全部解完了
這裡紀錄我自己的想法過程跟學習狀況
題目是:
Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.
You may assume that each input would have exactly one solution.
Input: numbers={2, 7, 11, 15}, target=9
Output: index1=1, index2=2

leetcode 151 - Reverse Words in a String

其實leetcode已經不止150題了,有151題
最後一題是在2014-03-05新增的

題目是

 

Reverse Words in a String

Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue",
return "blue is sky the".


第一次花了48ms
程式碼是用迴圈硬幹
第二次花了36ms
修正了回圈硬幹 改用C++的strtok(stringstream/getline)來分割字串

我提交的方式 C++,其餘可以選的語言還有Java跟python
真的有心用C++把151拼完後,再來考慮用python寫看看