更新代码和简历投递情况

This commit is contained in:
xiongraorao
2018-08-20 21:42:18 +08:00
parent 567613ec8a
commit f4160043bd
11 changed files with 452 additions and 35 deletions

View File

@ -0,0 +1,44 @@
package com.raorao.leetcode.q001;
import java.util.HashMap;
import java.util.Map;
/**
* 题目描述:给定一个整数数组和一个目标值,找出数组中和为目标值的两个数。你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用。
*
* @author Xiong Raorao
* @since 2018-08-20-16:54
*/
public class TwoSum {
public static void main(String[] args) {
int[] input = new int[] {12, 7, 11, 15};
int target = 18;
int[] ret = new TwoSum().twoSum(input, target);
System.out.println("ret= " + ret[0] + ", " + ret[1]);
}
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
int[] ret = new int[2];
for (int i = 0; i < nums.length; i++) {
int element = target - nums[i];
if (map.containsKey(element) && map.get(element) != i) {
if (i < map.get(element)) {
ret[0] = i;
ret[1] = map.get(element);
} else {
ret[0] = map.get(element);
ret[1] = i;
}
return ret;
}
map.put(nums[i], i);
}
return new int[0];
}
}

View File

@ -0,0 +1,79 @@
package com.raorao.leetcode.q002;
import java.util.List;
/**
* 两数相加.
*
* 给定两个非空链表来表示两个非负整数。位数按照逆序方式存储,它们的每个节点只存储单个数字。将两数相加返回一个新的链表。
*
* @author Xiong Raorao
* @since 2018-08-20-17:27
*/
public class AddTwoNumbers {
public static void main(String[] args) {
// ListNode l1 = new ListNode(2);
// l1.next = new ListNode(4);
// l1.next.next = new ListNode(3);
// ListNode l2 = new ListNode(5);
// l2.next = new ListNode(6);
// l2.next.next = new ListNode(4);
ListNode l1 = new ListNode(5);
ListNode l2 = new ListNode(5);
ListNode ret = new AddTwoNumbers().addTwoNumbers(l1, l2);
while (ret != null) {
System.out.print(ret.val + " ");
ret = ret.next;
}
}
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
int bit = 0; // 进位标识
ListNode ret = new ListNode(0);
ListNode root = ret;
ListNode node1 = l1;
ListNode node2 = l2;
while (node1 != null || node2 != null || bit > 0) {
int sum = 0;
if (node1 != null && node2 != null) {
sum = node1.val + node2.val + bit;
} else if (node2 != null) {
sum = node2.val + bit;
} else if (node1 != null) {
sum = node1.val + bit;
} else {
sum = bit;
}
if (sum > 9) {
bit = sum / 10;
// 链表尾插法
ret.next = new ListNode(sum % 10);
ret = ret.next;
} else {
ret.next = new ListNode(sum);
ret = ret.next;
bit = 0;
}
if (node1 != null) {
node1 = node1.next;
}
if (node2 != null) {
node2 = node2.next;
}
}
return root.next;
}
static class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
}
}
}

View File

@ -0,0 +1,43 @@
package com.raorao.leetcode.q003;
import java.util.HashMap;
import java.util.Map;
/**
* 无重复的最长子串.
*
* @author Xiong Raorao
* @since 2018-08-20-19:31
*/
public class MaxSubString {
public static void main(String[] args) {
String input = "abcabcbb";
int result = new MaxSubString().lengthOfLongestSubstring(input);
System.out.println(result);
}
public int lengthOfLongestSubstring(String s) {
if (s == null || s.length() == 0) {
return 0;
}
Map<Character, Integer> map = new HashMap<>();
int result = 1;
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (!map.containsKey(s.charAt(i))) {
map.put(s.charAt(i), i);
count++;
} else {
count = 0;
i = map.get(s.charAt(i));
map.clear();
}
if (result < count) {
result = count;
}
}
return result;
}
}

View File

@ -0,0 +1,36 @@
package com.raorao.leetcode.q088;
/**
* 归并两个有序数组.
*
* @author Xiong Raorao
* @since 2018-08-20-15:37
*/
public class MergeArray {
public static void main(String[] args) {
int[] nums1 = new int[] {1, 2, 3, 0, 0, 0};
int[] nums2 = new int[] {2, 5, 6};
new MergeArray().merge(nums1, 3, nums2, 3);
System.out.println(" ");
}
public void merge(int[] nums1, int m, int[] nums2, int n) {
int[] temp = new int[m + n];
int i = 0;
int j = 0;
int t = 0;
while (i < m && j < n) {
temp[t++] = nums1[i] < nums2[j] ? nums1[i++] : nums2[j++];
}
while (i < m) {
temp[t++] = nums1[i++];
}
while (j < n) {
temp[t++] = nums2[j++];
}
// temp copy to nums1
System.arraycopy(temp, 0, nums1, 0, m + n);
}
}

View File

@ -0,0 +1,60 @@
package com.raorao.leetcode.q141;
import java.util.ArrayList;
import java.util.List;
/**
* 判断链表是否存在环.
*
* 两种方法:一种采用外存来存储节点 另外一种,采用快慢指针的方法
*
* @author Xiong Raorao
* @since 2018-08-20-15:49
*/
public class IsLinkCycle {
public boolean hasCycle(ListNode head) {
if (head == null) {
return false;
}
List<ListNode> nodes = new ArrayList<>();
ListNode node = head;
while (node != null) {
if (!nodes.contains(node)) {
nodes.add(node);
node = node.next;
} else {
return true;
}
}
return false;
}
public boolean hasCycle2(ListNode head) {
if (head == null || head.next == null) {
return false;
}
ListNode slow = head;
ListNode fast = head.next;
while (fast != null && fast.next != null) {
if (slow == fast) {
return true;
}
slow = slow.next;
fast = fast.next.next;
}
return false;
}
static class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
next = null;
}
}
}

View File

@ -0,0 +1,78 @@
package com.raorao.leetcode.q215;
import java.util.PriorityQueue;
/**
* 求未排序数组的第K大元素.
*
* @author Xiong Raorao
* @since 2018-08-20-16:34
*/
public class Kth {
public static void main(String[] args) {
int[] input = new int[] {3, 2, 1, 5, 6, 4};
int k = 2;
int result = new Kth().findKthLargest2(input, k);
System.out.println(result);
//Arrays.stream(input).forEach(e -> System.out.print(e + " "));
}
/**
* 解法一:构建大顶堆
*/
public int findKthLargest(int[] nums, int k) {
PriorityQueue<Integer> queue = new PriorityQueue<>();
for (int num : nums) {
queue.add(num);
if (queue.size() > k) {
queue.poll();
}
}
return queue.peek();
}
/**
* 解法二快速选择时间复杂度O(N)空间复杂度O(1)
*/
public int findKthLargest2(int[] nums, int k) {
k = nums.length - k;
int l = 0, h = nums.length - 1;
while (l < h) {
int j = partition(nums, l, h);
if (j == k) {
break;
} else if (j < k) {
l = j + 1;
} else {
h = j - 1;
}
}
return nums[k];
}
private int partition(int[] a, int l, int h) {
int i = l, j = h + 1;
while (true) {
while (a[++i] < a[l] && i < h) {
}
while (a[--j] > a[l] && j > l) {
}
if (i >= j) {
break;
}
swap(a, i, j);
}
swap(a, l, j);
return j;
}
private void swap(int[] a, int i, int j) {
int t = a[i];
a[i] = a[j];
a[j] = t;
}
}

View File

@ -0,0 +1,40 @@
package com.raorao.leetcode.q345;
import java.util.Arrays;
import java.util.List;
/**
* 反转元音字母.
*
* @author Xiong Raorao
* @since 2018-08-20-11:32
*/
public class ReverseVowels {
private List<Character> vowels = Arrays.asList('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U');
public static void main(String[] args) {
String input = "hello";
String out = new ReverseVowels().reverseVowels(input);
System.out.println(out);
}
public String reverseVowels(String s) {
int i = 0;
int j = s.length() - 1;
char[] result = new char[s.length()];
while (i <= j) {
char ci = s.charAt(i);
char cj = s.charAt(j);
if (!vowels.contains(ci)) {
result[i++] = ci;
} else if (!vowels.contains(cj)) {
result[j--] = cj;
} else {
result[i++] = cj;
result[j--] = ci;
}
}
return new String(result);
}
}

View File

@ -0,0 +1,33 @@
package com.raorao.leetcode.q633;
/**
* 判断一个数是否为两个数的平方和.
*
* 双指针问题
*
* @author Xiong Raorao
* @since 2018-08-20-11:25
*/
public class JudgeSquareSum {
public static void main(String[] args) {
System.out.println(judgeSquareSum(1000));
}
public static boolean judgeSquareSum(int c) {
int i = 0;
int j = (int) Math.sqrt(c);
while (i <= j) {
int sum = i * i + j * j;
if (sum == c) {
//System.out.println("i = " + i + ", j = " + j);
return true;
} else if (sum < c) {
i++;
} else {
j--;
}
}
return false;
}
}

View File

@ -0,0 +1,36 @@
package com.raorao.leetcode.q680;
/**
* 验证回文字符串.
*
* @author Xiong Raorao
* @since 2018-08-20-15:07
*/
public class ValidPalindrome {
public static void main(String[] args) {
String input = "abcba";
boolean res = new ValidPalindrome().validPalindrome(input);
System.out.println(res);
}
public boolean validPalindrome(String s) {
int i = -1;
int j = s.length();
while (++i < --j) {
if (s.charAt(i) != s.charAt(j)) {
return isPalindrome(s, i, j - 1) || isPalindrome(s, i + 1, j);
}
}
return true;
}
private boolean isPalindrome(String s, int i, int j) {
while (i < j) {
if (s.charAt(i++) != s.charAt(j--)) {
return false;
}
}
return true;
}
}

View File

@ -142,37 +142,3 @@ linux指令
P/V 操作 P/V 操作
磁盘调度,虚拟内存 磁盘调度,虚拟内存
死锁,中断 死锁,中断
## 4. 学习路线
我自己的学习路线规划:技能的主线是 **Java 语言基础 -> Spring 框架开发业务 -> 分布式系统解决高并发,基础方面 算法,网络协议,操作系统**
概念性的程度:了解是啥,能够口述含义
使用的程度:可以熟练使用,比如调用 API写 SQL 查询
原理的程度:能够讲清楚底层实现
提出见解的程度:从任意技术可以引申出相关技术,并能够分析联系和区别,提出自己的见解和体会
以上四种程度逐层加深,当然越深越好,通常前两种程度只能称之为“了解”;而写上简历迎接考核的,至少需要掌握到「原理」的程度。
## 5. 参考书籍
《算法》(第四版)图以前章节
《剑指 Offer》
《Java 编程思想》
《Java多线程编程核心技术》(高洪岩 著)
《Java 并发编程实战》
《深入理解 Java 虚拟机》
《Java 8 实战》
《鸟哥的 Linux 私房菜》
《MySQL 必知必会》
《Maven 实战》
《图解 HTTP》
《敏捷软件开发》
《架构探险-从零开始写 Java Web 框架》
《Spring 3.x 企业应用开发实战》
《Head First 设计模式》
《大型网站技术架构》(李智慧 著)
《大型网站系统与 Java 中间件实践》
## 6. 面试技巧

View File

@ -34,7 +34,9 @@ Java后端开发大数据、分布式应用等
顺丰科技 | 7.30 | 8.20 | | | 顺丰科技 | 7.30 | 8.20 | | |
贝壳网 | 8.4 | 8.20 | 8.18 | 贝壳网 | 8.4 | 8.20 | 8.18 |
美团 | 8.6(内推) | 8.20 | <li> 第一批9.6 19:00 (第一批未参加直面的) | <li> 第一批8.16-9.5(内推的人) <li> 第二批9.6-9.14(武汉现场面) 美团 | 8.6(内推) | 8.20 | <li> 第一批9.6 19:00 (第一批未参加直面的) | <li> 第一批8.16-9.5(内推的人) <li> 第二批9.6-9.14(武汉现场面)
招银网络 | 8.7(内推) | 8.20 |
小米科技 | 8.20(柚子妹内推) | 8.20 | 时间不详
京东 | 8.4 | 8.20 | <li>简历截止8.30</li><li>笔试时间 9.9</li><li>面试时间 9.16-9.20</li>
# 2 复习内容 # 2 复习内容