File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- 学习笔记
1+ 学习笔记
2+
3+ HashTable
4+ 通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度。
5+ 这个映射函数叫做散列函数,存放记录的数组叫做哈希表。
6+
7+ 二叉树的遍历
8+ 1 . 前序(Pre-order): 根 - 左 - 右
9+ 2 . 中序(In-order): 左 - 根 - 右
10+ 3 . 后序(Post-order): 左 - 右 - 根
11+
12+ 二叉搜索树
13+ 也称二叉排序树,有序二叉树,排序二叉树,是指一颗空树或者具有下列性质的二叉树:
14+ 1 . 左子树上所有节点的值均小于它的根节点的值;
15+ 2 . 右子树上所有节点的值均大于它的根节点的值;
16+ 3 . 以此类推:左右子树也分别称为二叉查找树。
17+ 中序遍历:升序排列
18+
19+ 堆
20+ 将根节点最大的堆叫做大顶堆或大根堆,根节点最小的堆叫做小顶堆或小根堆。
21+
22+ 二叉堆
23+ 通过完全二叉堆来实现
24+
25+ 图
26+ 无向无权图、无向有权图、有向有权图、无向有权图
27+
Original file line number Diff line number Diff line change 1+ /**
2+ * 我们把只包含因子 2、3 和 5 的数称作丑数(Ugly Number)。求按从小到大的顺序的第 n 个丑数。
3+ */
4+ class Solution {
5+ public int nthUglyNumber (int n ) {
6+ int a = 0 , b = 0 , c = 0 ;
7+ int [] dp = new int [n ];
8+ dp [0 ] = 1 ;
9+ for (int i = 1 ; i < n ; i ++) {
10+ int n2 = dp [a ] * 2 , n3 = dp [b ] * 3 , n5 = dp [c ] * 5 ;
11+ dp [i ] = Math .min (Math .min (n2 , n3 ), n5 );
12+ if (dp [i ] == n2 ) a ++;
13+ if (dp [i ] == n3 ) b ++;
14+ if (dp [i ] == n5 ) c ++;
15+ }
16+ return dp [n - 1 ];
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ /**
2+ * 给定一个字符串数组,将字母异位词组合在一起。字母异位词指字母相同,但排列不同的字符串。
3+ */
4+ class Solution {
5+ public List <List <String >> groupAnagrams (String [] strs ) {
6+ if (strs .length == 0 ) return new ArrayList ();
7+ Map <String , List > ans = new HashMap <String , List >();
8+ int [] count = new int [26 ];
9+ for (String s : strs ) {
10+ Arrays .fill (count , 0 );
11+ for (char c : s .toCharArray ()) count [c - 'a' ]++;
12+
13+ StringBuilder sb = new StringBuilder ("" );
14+ for (int i = 0 ; i < 26 ; i ++) {
15+ sb .append ('#' );
16+ sb .append (count [i ]);
17+ }
18+ String key = sb .toString ();
19+ if (!ans .containsKey (key )) ans .put (key , new ArrayList ());
20+ ans .get (key ).add (s );
21+ }
22+ return new ArrayList (ans .values ());
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments