Fork me on GitHub
Mr.Huang

  • 首页
  • 关于
  • 标签
  • 分类
  • 归档
  • 随笔

arts1

发表于 2019-03-21 | 分类于 ARTS

第一周

Algorithm

先从刷LeetCode开始吧!之前一直没刷过,坚持 刷 刷 刷

Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

1
2
3
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].

刚开始使用暴力解法直接双重循环

1
2
3
4
5
6
7
8
9
10
Public int[] twoSum(int[] nums, int target) {
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
if (nums[j] == target - nums[i]) {
return new int[] { i, j };
}
}
}
throw new IllegalArgumentException("No two sum solution");
}

写完之后看了下被人的解法
其中

1
2
3
4
5
6
7
8
9
10
11
public int[] twoSum(int[] nums, int target) {
Map<Integer,Integer> map = new HashMap<>();
for(int i = 0;i < nums.length;i++){
int v = target - nums[i];
if(map.containsKey(v)){
return new int[]{map.get(v),i};
}
map.put(nums[i],i);
}
throw new IllegalArgumentException("No two sum solution");
}

这个是如果没有刷过自己是想不到的利用map的containsKey减少了一层循环然后去看了HashMap的这个的实现是调用了如下方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
final Node<K,V> getNode(int hash, Object key) {
Node<K,V>[] tab; Node<K,V> first, e; int n; K k;
if ((tab = table) != null && (n = tab.length) > 0 &&
(first = tab[(n - 1) & hash]) != null) {
if (first.hash == hash && // always check first node
((k = first.key) == key || (key != null && key.equals(k))))
return first;
if ((e = first.next) != null) {
if (first instanceof TreeNode)
return ((TreeNode<K,V>)first).getTreeNode(hash, key);
do {
if (e.hash == hash &&
((k = e.key) == key || (key != null && key.equals(k))))
return e;
} while ((e = e.next) != null);
}
}
return null;
}

这就是所谓的用空间换时间吧

Rewiew

Tip

在用apache搭建 webdav 时遇到文件名称中文乱码
在这里插入图片描述
看这里主要描述了IndexOptions配置的作用
在httpd.conf 加上 IndexOptions Charset=UTF-8 即可解决
在这里插入图片描述

我的ARTS 记录

发表于 2019-03-17 | 分类于 ARTS

第0周,准备工作(2019.3.17):

解释ARTS 及 相关计划:

  • Algorithm : 算法相关,写数据结构相关的代码,如果没得写,就去刷至少一道leetcode
  • Review: 翻译一遍英文文章。
  • Tip:总结一下工作中遇到的比较有意思的地方
  • Share:汇总一篇有深度的文章,不能粘贴代码,文字数要过1000

Hello World

发表于 2019-03-16

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

yu jian Huang

yu jian Huang

just so so

3 日志
1 分类
1 标签
© 2019 yu jian Huang