PIXNET Logo登入

CONY的世界

跳到主文

在這裡我不是要向大家講述我的生活,只是想留著一些回憶

部落格全站分類:生活綜合

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 12月 27 週三 201708:37
  • Leetcode 3 @ Java

3. Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequenceand not a substring.
 
這題不是用DP,因為一但遇到重疊的基本上counting是直接歸零
看解答也是用two pointer 掃過所有可能,l 負責記錄開頭,r 負責記錄結尾,
用兩個紀錄的好處是當要清除重複的字元時,前面非重複字元其實也要從set清除掉,
所以 l 可以幫助紀錄到底需要清掉哪些字元,中間過程中我們會掃過所有可能的不重複字串,
所以要有一個int 去記錄這之中最長的字串在最後return
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(14)

  • 個人分類:Algorithm medium
▲top
  • 12月 26 週二 201713:06
  • Leetcode Math 360 @ Java

360. Sort Transformed Array
注意這題之所以變難是因為O(n),因為不能用sorting,不然會變成O(nlogn)
用到的概念是數學的概念拋物線
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(9)

  • 個人分類:
▲top
  • 10月 05 週四 201709:33
  • Floyd's Cycle - Tortoise and Hare

通常用來detect loop,判斷從哪段開始有loop 
解法可以想像是龜兔賽跑,兔子兩倍速,烏龜一倍速前進
 
假設c是起點距離loop的距離,k是起點距離第一次相遇點的距離,loop 長度是L
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(153)

  • 個人分類:學習
▲top
  • 10月 03 週二 201703:08
  • Leetcode random 162,16 @ Java

 
162. Find Peak Element

A peak element is an element that is greater than its neighbors.
Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(2)

  • 個人分類:Algorithm medium
▲top
  • 10月 03 週二 201703:08
  • Leetcode Trie 211,208 @Java

211. Add and Search Word - Data structure design

Design a data structure that supports the following two operations:
void addWord(word)
bool search(word)
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(36)

  • 個人分類:Algorithm medium
▲top
  • 9月 29 週五 201711:29
  • java - covariant and invariant

在研究為什麼 List<List<Integer>> res = new ArrayList<>(); 
 為什麼可以這樣初始,然後研究到這個
 
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(90)

  • 個人分類:學習
▲top
  • 9月 29 週五 201705:40
  • Leetcode Array 442,15 @Java

442. Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
Find all the elements that appear twice in this array.
Could you do it without extra space and in O(n) runtime?
 
Example:
Input:
[4,3,2,7,8,2,3,1]
Output:
[2,3]
 Success: 
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(25)

  • 個人分類:
▲top
  • 9月 27 週三 201712:56
  • Leetcode Greedy 134, 55 @Python

134. Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once, otherwise return -1.
Note:
The solution is guaranteed to be unique.
 
紀錄這題我一開始想到的就是想找扣最多當最後,然後向後找正值當起頭
結果很難寫.....就去解答了
這題用到蠻重要的一個觀念
When sum(i, j) < 0, start = i + 1
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(14)

  • 個人分類:Algorithm medium
▲top
  • 8月 03 週四 201717:31
  • Leetcode Greedy 134, 55 @Python

134. Gas Station

There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once, otherwise return -1.
Note:
The solution is guaranteed to be unique.
 
紀錄這題我一開始想到的就是想找扣最多當最後,然後向後找正值當起頭
結果很難寫.....就去解答了
這題用到蠻重要的一個觀念
When sum(i, j) < 0, start = i + 1
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(8)

  • 個人分類:Algorithm medium
▲top
  • 7月 31 週一 201713:47
  • Leetcode Stack 71,402 @Python

71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it.
For example,
path = "/home/", => "/home"
path = "/a/./b/../../c/", => "/c"
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(1) 人氣(31)

  • 個人分類:
▲top
«1...34561»

個人資訊

angledark0123
暱稱:
angledark0123
分類:
生活綜合
好友:
累積中
地區:

Top Posts

  • (16,627)什麼是Library(函式庫,大陸稱庫)
  • (863)我不知道風是在哪一個方向吹 徐志摩
  • (397)「大考大玩,小考小玩」的真實意義
  • (330)台北Mei’s Tea Bar ~好吃又特別的蘋果鬆餅
  • (265)yuv player 實作筆記
  • (162)寫程式語言人的痛(同感)
  • (133)何其芳〈夢中道路〉
  • (9)兩天一夜台北遊 part1 -元定食
  • (3)告訴你我在忙什麼
  • (1)多事之際

文章分類

toggle leetcode (3)
  • Algorithm medium (32)
  • easy (5)
  • hard (6)
  • google (1)
  • 拜家 (4)
  • 學習 (102)
  • 生活隨筆 (49)
  • 旅遊 (16)
  • 美食 (9)
  • 未分類文章 (1)

最新文章

  • Leetcode Tree,Linkedlist 114 @ Java
  • Leetcode DP 764 @ Java
  • Leetcode Greedy 316 @ Java
  • Leetcode DP 140 @Java
  • Google CodeJam I/O for women 2/17- Graph-Centrist
  • Leetcode contest-2/17- BFS 785 @ Java
  • Leetcode Math 670 @Java
  • Leetcode Graph 269 @Java
  • Leetcode BFS 127 @ Java
  • Leetcode UnionFind 261 @Java

最新留言

  • [24/08/12] 訪客 於文章「減重整理...」留言:
    瘦身要有效最重要的是提升自身代謝力 唯有代謝提高後,又...
  • [23/09/23] 新飛Hsinfei 於文章「最近英文課一波三折...」留言:
    都是為了連假!辛苦的補班英文該怎麼說?連假英文呢? http...
  • [22/04/27] 訪客 於文章「Create customized MP...」留言:
    原本在搜尋引擎找出一堆 Blog 文章,不知哪幾篇值得花時間...
  • [20/12/17] 哈 於文章「Leetcode Tree,Linked...」留言:
    爛...
  • [17/09/18] 老菜 於文章「Win7上灌vc6...」留言:
    您好,請問您還有FileTool這個補丁嗎?MicroSof...
  • [17/08/19] Tim Feng 於文章「Leetcode Stack 71,40...」留言:
    你好,我最近在學python,分析各位先賢們的專案。從200...
  • [16/11/09] Blake Hung 於文章「C/C++之指標 (pointer),參...」留言:
    非常詳盡,謝謝!...
  • [16/06/18] 路人 於文章「什麼是Library(函式庫,大陸稱庫)...」留言:
    黃色字很不清楚,不容易看。...
  • [15/04/20] 訪客 於文章「vim附件:cscope+ctag 使用...」留言:
    Ctrl+/ 再按s 表示:cs find s命令 ==>C...
  • [14/03/20] 射手白馬 於文章「心情雜記...」發表了一則私密留言

文章精選

文章搜尋

誰來我家

參觀人氣

  • 本日人氣:
  • 累積人氣: