Skip to content

Commit bec0d05

Browse files
author
liwentian
committed
fd
1 parent a3dc5f9 commit bec0d05

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
package com.leetcode.amazon;
22

3+
import java.util.HashMap;
4+
import java.util.LinkedHashMap;
5+
36
/**
47
* Created by liwentian on 2017/10/16.
58
*/
69

710
public class Main {
811

912
public static void main(String[] args) {
10-
EncodeAndDecodeTinyUrl s = new EncodeAndDecodeTinyUrl();
11-
String shortUrl = s.encode("http://baidu.com");
12-
System.out.println(shortUrl);
13+
HashMap<String, String> map = new HashMap<>();
14+
map.put("one", "ones");
15+
map.put("two", "twos");
1316

14-
System.out.println(s.decode(shortUrl));
17+
for (Integer key : map.keySet()) {
18+
System.out.println(key);
19+
}
1520
}
1621
}

doc/系统设计/ReadME.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
1, 如何高并发
2+
2,如何解决单点故障
3+
4+
3,如何高速读
5+
缓存,lrucache,读写分离,多台机器,缓存命中,一致性hash
6+
7+
4,如何高速写
8+
5,如何负载均衡
9+
6,如何海量统计
10+
11+
12+
13+
数据库的垂直拆分和水平拆分
14+
15+
中间件:
16+
1,RPC
17+
2,消息
18+
3,数据
19+
20+
读多写少
21+
copyonwrite, readlock

ebook/tree/Tree.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,12 @@ \subsubsection{Solution}
289289
int leftMax = maxPathSum(root.left, left);
290290
int rightMax = maxPathSum(root.right, right);
291291
if (max != null) {
292-
max[0] = max(left[0], right[0], 0) + root.val; // 此处容易错
292+
// 三种情况:root, root+left, root+right
293+
max[0] = max(left[0], right[0], 0) + root.val;
293294
}
294295

295296
// 容易错,要考虑到所有可能的情况
297+
// 左边里面的,右边里面的,光root的,左中右,左中,中右
296298
return max(leftMax, rightMax, root.val, left[0] + right[0] + root.val,
297299
left[0] + root.val, right[0] + root.val);
298300
}

leetcode.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<content url="file://$MODULE_DIR$">
1414
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
1515
</content>
16-
<orderEntry type="inheritedJdk" />
16+
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
1717
<orderEntry type="sourceFolder" forTests="false" />
1818
</component>
1919
</module>

solution/src/main/java/com/inuker/solution/system/DesignTinyURL.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@ public class DesignTinyURL {
1818
* 3. Mapping an identifier to an URL and its reversal - Does this problem ring a bell to you?
1919
*
2020
* 4. How do you store the URLs? Does a simple flat file database work?
21-
* 采用分布式,负载均衡随机分发到一台机器,KV数据库,以短网址为key,长网址为value
21+
* key为short, value为url, 则总共空间(6 + 30) * 30G = 1080G,单机恐怕不够,而且容易形成
22+
* 单点故障。最好分散到多个机器上,一致性hash负载均衡,KV数据库,以短网址为key,长网址为value
23+
* 每个机器上有固定前缀,后面的序号依次递增即可
2224
*
2325
* 5. What is the bottleneck of the system? Is it read-heavy or write-heavy?
2426
* 读显然比写多,比如用户在微博分享了一个资源,以短链接的形式。很多用户访问这个链接,则读远大于写。
25-
*
27+
* 所以要用cache,读写分离
2628
*
2729
* 6. Estimate the maximum number of URLs a single machine can store.
2830
*
2931
* 7. Estimate the maximum number of queries per second (QPS) for decoding a shortened URL in a single machine.
3032
*
3133
* 8. How would you scale the service? For example, a viral link which is shared in social media could result in a peak QPS at a moment's notice.
34+
*
3235
*
3336
* 9. How could you handle redundancy? i,e, if a server is down, how could you ensure the service is still operational?
3437
* 一致性哈希,虚拟节点

0 commit comments

Comments
 (0)