From 9463b92f84f2d4b290a0a8abe08fb6930d3be081 Mon Sep 17 00:00:00 2001 From: Pickle <850885154@qq.com> Date: Sat, 11 May 2019 22:54:13 +0800 Subject: [PATCH 1/5] week4 homework --- Week_04/id_134/LeetCode_169_134.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Week_04/id_134/LeetCode_169_134.java diff --git a/Week_04/id_134/LeetCode_169_134.java b/Week_04/id_134/LeetCode_169_134.java new file mode 100644 index 00000000..d71f3d5c --- /dev/null +++ b/Week_04/id_134/LeetCode_169_134.java @@ -0,0 +1,21 @@ +public class Solution { + public int majorityElement(int[] num) { + + int ans = 0, cnt = 0; + for(int i=0; i Date: Sat, 11 May 2019 22:54:43 +0800 Subject: [PATCH 2/5] week4 homework --- Week_04/id_134/LeetCode_455_134.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Week_04/id_134/LeetCode_455_134.java diff --git a/Week_04/id_134/LeetCode_455_134.java b/Week_04/id_134/LeetCode_455_134.java new file mode 100644 index 00000000..448768cc --- /dev/null +++ b/Week_04/id_134/LeetCode_455_134.java @@ -0,0 +1,14 @@ +class Solution { + public int findContentChildren(int[] g, int[] s) { + Arrays.sort(g); + Arrays.sort(s); + int cnt = 0; + for (int gi = 0, si = 0; gi < g.length && si < s.length; si++) { + if (g[gi] <= s[si]) { + cnt ++; + gi ++; + } + } + return cnt; + } +} From 51cd526c27b7ab85d1bbdef247b34155d43b0f20 Mon Sep 17 00:00:00 2001 From: Pickle <850885154@qq.com> Date: Sun, 12 May 2019 19:53:24 +0800 Subject: [PATCH 3/5] week4 homework --- Week_04/id_134/LeetCode_720_134.java | 73 ++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Week_04/id_134/LeetCode_720_134.java diff --git a/Week_04/id_134/LeetCode_720_134.java b/Week_04/id_134/LeetCode_720_134.java new file mode 100644 index 00000000..f2e98c74 --- /dev/null +++ b/Week_04/id_134/LeetCode_720_134.java @@ -0,0 +1,73 @@ +class Solution { + TrieNode root = new TrieNode(); + StringBuilder curWord = new StringBuilder(); + String ret = null; + public String longestWord(String[] words) { + if (words == null) + return null; + for (String word : words) { + insert(word); + } + traverse(root); + return ret; + } + + public void traverse(TrieNode root) { + if (root.isLeaf()) { + if (curWord != null) { + if (ret == null || ret.length() < curWord.length() || + (ret.length() == curWord.length() && ret.compareTo(curWord.toString()) > 0)) { + ret = curWord.toString(); + } + } + return; + } + for (int i=0; i<26; i++) { + if (root.sons[i] != null && root.sons[i].isEnd) { + curWord.append(root.sons[i].val); + traverse(root.sons[i]); + curWord.deleteCharAt(curWord.length()-1); + } + } + } + + public void insert(String word) { + TrieNode node = root; + for (int i=0; i Date: Sun, 12 May 2019 21:20:07 +0800 Subject: [PATCH 4/5] week4 homework --- Week_04/id_134/LeetCode_211_134.java | 76 ++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Week_04/id_134/LeetCode_211_134.java diff --git a/Week_04/id_134/LeetCode_211_134.java b/Week_04/id_134/LeetCode_211_134.java new file mode 100644 index 00000000..e6620a13 --- /dev/null +++ b/Week_04/id_134/LeetCode_211_134.java @@ -0,0 +1,76 @@ +class WordDictionary { + + TrieNode root; + /** Initialize your data structure here. */ + public WordDictionary() { + root = new TrieNode(); + } + + /** Adds a word into the data structure. */ + public void addWord(String word) { + if (word == null || word.length() <= 0) + return; + TrieNode node = root; + for (int i=0; i Date: Sun, 12 May 2019 22:30:05 +0800 Subject: [PATCH 5/5] week4 homework --- Week_04/id_134/LeetCode_784_134.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Week_04/id_134/LeetCode_784_134.java diff --git a/Week_04/id_134/LeetCode_784_134.java b/Week_04/id_134/LeetCode_784_134.java new file mode 100644 index 00000000..9ac25e81 --- /dev/null +++ b/Week_04/id_134/LeetCode_784_134.java @@ -0,0 +1,22 @@ +class Solution { + List ret = new ArrayList<>(); + public List letterCasePermutation(String S) { + if (S == null || S.length() <= 0) + return ret; + dfs(S.toCharArray(), 0); + return ret; + } + + public void dfs(char[] chs, int idx) { + if (chs.length == idx) { + ret.add(new String(chs)); + return; + } + if (Character.isLetter(chs[idx])) { + chs[idx] = Character.toLowerCase(chs[idx]); + dfs(chs, idx+1); + chs[idx] = Character.toUpperCase(chs[idx]); + } + dfs(chs, idx+1); + } +}