https://leetcode.com/problems/summary-ranges/ Summary Ranges Total Accepted: 22806 Total Submissions: 114600 Difficulty: Easy Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. Code class Solution(object): def summaryRanges(self, nums): “”” :type nums: List[int] :rtype: List[str] “”” res = [] s = “” for i, v in enumerate(nums): if …
Author Archives: czxttkl
Leetcode 288: Unique Word Abbreviation
https://leetcode.com/problems/unique-word-abbreviation/ Unique Word Abbreviation Total Accepted: 984 Total Submissions: 5829 Difficulty: Easy An abbreviation of a word follows the form <first letter><number><last letter>. Below are some examples of word abbreviations: a) it –> it (no abbreviation) 1 b) d|o|g –> d1g 1 1 1 1—5—-0—-5–8 c) i|nternationalizatio|n –> i18n 1 1—5—-0 d) l|ocalizatio|n –> l10n …
Leetcode 20: Valid Parenthesis
https://leetcode.com/problems/valid-parentheses/ Valid Parentheses Total Accepted: 72044 Total Submissions: 267703 Difficulty: Easy Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not. My code: …
Leetcode 140: Word Break II
https://leetcode.com/problems/word-break-ii/ Word Break II Total Accepted: 41843 Total Submissions: 232195 Difficulty: Hard Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, given s = "catsanddog", dict = ["cat", "cats", "and", "sand", …
Leetcode 139: WordBreak
https://leetcode.com/problems/word-break/ Word Break Total Accepted: 65299 Total Submissions: 278950 Difficulty: Medium Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, givens = "leetcode",dict = ["leet", "code"]. Return true because "leetcode" can be segmented as "leet code". …
Leetcode 23: Merge k sorted lists
https://leetcode.com/problems/merge-k-sorted-lists/ Merge k Sorted Lists Total Accepted: 59265 Total Submissions: 278075 Difficulty: Hard Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Code 1: import heapq # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None …
Leetcode 269: Alien Dictionary
https://leetcode.com/problems/alien-dictionary/ Alien Dictionary Total Accepted: 1390 Total Submissions: 8315 Difficulty: Hard There is a new alien language which uses the latin alphabet. However, the order among letters are unknown to you. You receive a list of words from the dictionary, where words are sorted lexicographically by the rules of this new language. Derive the order …
Review: The Google File System
Original paper: http://static.googleusercontent.com/media/research.google.com/en//archive/gfs-sosp2003.pdf Cons and pros on Quora: https://www.quora.com/Reviews-of-Google-File-System Paper discussion: http://pages.cs.wisc.edu/~swift/classes/cs736-fa08/blog/2008/11/the_google_file_system.html A blog discussion: http://kaushiki-gfs.blogspot.com/ A ppt discussion: http://www.slideshare.net/tutchiio/gfs-google-file-system A QA series: http://pages.cs.wisc.edu/~thanhdo/qual-notes/fs/fs4-gfs.txt GFS wiki: http://google-file-system.wikispaces.asu.edu/ 2.3 GFS uses one-master-mutiple-chunkservers mode. Client will query the master about the metadata of files, which reside in the master’s memory hence query is fast. The real data operation takes place at chunkservers. …
Leetcode 146: LRU cache
https://leetcode.com/problems/lru-cache/ LRU Cache Total Accepted: 50542 Total Submissions: 329169 Difficulty: Hard Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) – Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value) …
Leetcode 271: Encode and Decode Strings
https://leetcode.com/problems/encode-and-decode-strings/ Encode and Decode Strings Total Accepted: 1272 Total Submissions: 4999 Difficulty: Medium Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings. Machine 1 (sender) has the function: string encode(vector<string> strs) { // …