Skip to content

SZ001-1906019 #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Week_01/id_19/LeetCode_1047_19.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution {
public String removeDuplicates(String S) {

/**
* 去重可利用栈来解
* 与栈顶对比,重复移除,否则入栈
*/
// 将字符串转成字符
char[] chars = S.toCharArray();
Stack<Character> stack = new Stack<>();

for (int i = 0; i<chars.length; i++) {
if (stack.isEmpty() || stack.peek() != chars[i]) {
stack.push(chars[i]);
}else {
stack.pop();
}
}

StringBuilder sb = new StringBuilder();
for (char c: stack) {
sb.append(c);
}

return sb.toString();
}
}
14 changes: 14 additions & 0 deletions Week_01/id_19/LeetCode_24_19.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public ListNode swapPairs(ListNode head) {
// 终止条件只有一个结点或者无结点
if (head == null || head.next == null) {
return head;
}

ListNode nextNode = head.next;
// 递归条件 f(n) = f(n+1)
head.next = swapPairs(nextNode.next);
nextNode.next = head;
return nextNode;
}
}
22 changes: 22 additions & 0 deletions Week_01/id_19/LeetCode_26_19.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public int removeDuplicates(int[] nums) {

// 时间复杂度为O(n)
// 数组判断
if (nums.length == 0) {
return 0;
}
// 假设不相等的位置为1
int uniquePos = 1;
for(int i = 1;i < nums.length; i++) {
// 这里要注意数组越界问题
if (nums[i] != nums[i-1]) {
// 数组往前移动
nums[uniquePos] = nums[i];
uniquePos++;
}
}
return uniquePos;

}
}
2 changes: 2 additions & 0 deletions Week_01/id_19/NOTE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# 学习笔记

week_01

本周主要是学习了[线性表数据结构](http://note.youdao.com/noteshare?id=1a02479cdcbb9ffc7bb6dc587cbee0fc)。学习中基础知识发现都懂了,但在刷题时却没什么思路,最后回想起覃超老师传授的五毒神掌法及常见算法解题步骤一步步实践、反复练习及总结。
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.