From 99e9f0211842ee9c99f614c64d6b105d27937469 Mon Sep 17 00:00:00 2001 From: juan Date: Tue, 6 Sep 2022 20:11:55 +0800 Subject: [PATCH] vault backup: 2022-09-06 20:11:55 --- .obsidian/graph.json | 2 +- .obsidian/themes/Atom.css | 472 ------------------ .../pages/Leetcode Repeated-DNA-Sequences.md | 103 ++++ 3 files changed, 104 insertions(+), 473 deletions(-) delete mode 100644 .obsidian/themes/Atom.css create mode 100644 OJ notes/pages/Leetcode Repeated-DNA-Sequences.md diff --git a/.obsidian/graph.json b/.obsidian/graph.json index ea07bbe..8bb286a 100644 --- a/.obsidian/graph.json +++ b/.obsidian/graph.json @@ -39,6 +39,6 @@ "repelStrength": 10, "linkStrength": 1, "linkDistance": 250, - "scale": 1.3711753906745523, + "scale": 0.9747267101258579, "close": true } \ No newline at end of file diff --git a/.obsidian/themes/Atom.css b/.obsidian/themes/Atom.css deleted file mode 100644 index b2c7efb..0000000 --- a/.obsidian/themes/Atom.css +++ /dev/null @@ -1,472 +0,0 @@ -.theme-dark { - --background-primary: #272b34; - --background-primary-alt: #20242b; - --background-secondary: #20242b; - --background-secondary-alt: #1a1e24; - --background-accent: #000; - --background-modifier-border: #424958; - --background-modifier-form-field: rgba(0, 0, 0, 0.3); - --background-modifier-form-field-highlighted: rgba(0, 0, 0, 0.22); - --background-modifier-box-shadow: rgba(0, 0, 0, 0.3); - --background-modifier-success: #539126; - --background-modifier-error: #3d0000; - --background-modifier-error-rgb: 61, 0, 0; - --background-modifier-error-hover: #470000; - --background-modifier-cover: rgba(0, 0, 0, 0.6); - --text-accent: #61afef; - --text-accent-hover: #69bafd; - --text-normal: #dcddde; - --text-muted: #888; - --text-faint: rgb(81, 86, 99); - --text-error: #e16d76; - --text-error-hover: #c9626a; - --text-highlight-bg: rgba(255, 255, 0, 0.4); - --text-selection: rgba(0, 122, 255, 0.2); - --text-on-accent: #dcddde; - --interactive-normal: #20242b; - --interactive-hover: #353b47; - --interactive-accent: #4c78cc; - --interactive-accent-rgb: 76, 120, 204; - --interactive-accent-hover: #5082df; - --scrollbar-active-thumb-bg: rgba(255, 255, 255, 0.2); - --scrollbar-bg: rgba(255, 255, 255, 0.05); - --scrollbar-thumb-bg: rgba(255, 255, 255, 0.1); - --panel-border-color: #18191e; - --gray-1: #5C6370; - --gray-2: #abb2bf; - --red: #e06c75; - --orange: #d19a66; - --green: #98c379; - --aqua: #56b6c2; - --purple: #c678dd; - --blue: #61afef; - --yellow: #e5c07b; -} - -.theme-light { - --background-primary: #fafafa; - --background-primary-alt: #eaeaeb; - --background-secondary: #eaeaeb; - --background-secondary-alt: #dbdbdc; - --background-accent: #fff; - --background-modifier-border: #dbdbdc; - --background-modifier-form-field: #fff; - --background-modifier-form-field-highlighted: #fff; - --background-modifier-box-shadow: rgba(0, 0, 0, 0.1); - --background-modifier-success: #A4E7C3; - --background-modifier-error: #e68787; - --background-modifier-error-rgb: 230, 135, 135; - --background-modifier-error-hover: #FF9494; - --background-modifier-cover: rgba(0, 0, 0, 0.8); - --text-accent: #1592ff; - --text-accent-hover: #2d9dff; - --text-normal: #383a42; - --text-muted: #8e8e90; - --text-faint: #999999; - --text-error: #e75545; - --text-error-hover: #f86959; - --text-highlight-bg: rgba(255, 255, 0, 0.4); - --text-selection: rgba(0, 122, 255, 0.15); - --text-on-accent: #f2f2f2; - --interactive-normal: #eaeaeb; - --interactive-hover: #dbdbdc; - --interactive-accent-rgb: 21, 146, 255; - --interactive-accent: #5871ef; - --interactive-accent-hover: #445bd1; - --scrollbar-active-thumb-bg: rgba(0, 0, 0, 0.2); - --scrollbar-bg: rgba(0, 0, 0, 0.05); - --scrollbar-thumb-bg: rgba(0, 0, 0, 0.1); - --panel-border-color: #dbdbdc; - --gray-1: #383a42; - --gray-2: #383a42; - --red: #e75545; - --green: #4ea24c; - --blue: #3d74f6; - --purple: #a625a4; - --aqua: #0084bc; - --yellow: #e35649; - --orange: #986800; -} - -body { - -webkit-font-smoothing: auto; -} - -.titlebar { - background-color: var(--background-secondary-alt); -} - -.titlebar-inner { - color: var(--text-normal); -} - -.tooltip { - background-color: var(--background-secondary-alt); - color: var(--text-muted); -} - -.tooltip:not(.mod-right):not(.mod-left):not(.mod-top) .tooltip-arrow { - border-bottom-color: var(--background-secondary-alt) !important; -} - -.mod-right .tooltip-arrow { - border-right-color: var(--background-secondary-alt) !important; -} - -.mod-left .tooltip-arrow { - border-left-color: var(--background-secondary-alt) !important; -} - -.mod-top .tooltip-arrow { - border-top-color: var(--background-secondary-alt) !important; -} - -.dropdown { - cursor: pointer; - background-image: url(data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%234c78cc%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E); -} - -.dropdown:hover { - background-color: var(--background-modifier-form-field); -} - -.search-result-file-title { - color: var(--blue); -} - -li { - padding-top: 0.5px; - padding-bottom: 0.5px; -} - -a.tag, a.tag:hover { - color: var(--yellow); - background-color: var(--background-primary-alt); - padding: 2px 4px; - border-radius: 4px; -} - -.markdown-preview-view .task-list-item-checkbox { - -webkit-appearance: none; - box-sizing: border-box; - border: 1px solid var(--text-muted); - border-radius: 2px; - position: relative; - width: 1.3em; - height: 1.3em; - margin: 0; - filter: none; - outline: none; - margin-right: 4px; - margin-bottom: 2px; - cursor: pointer; - vertical-align: baseline; -} - -.markdown-preview-view .task-list-item-checkbox:checked { - border: none; - background-color: var(--interactive-accent); -} - -.markdown-preview-view .task-list-item-checkbox:checked::before { - content: ' '; - position: absolute; - background-color: white; - left: 2px; - top: 2px; - right: 2px; - bottom: 2px; - -webkit-mask-image: url('data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'%3E%3Cpolygon points=\'5.5 11.9993304 14 3.49933039 12.5 2 5.5 8.99933039 1.5 4.9968652 0 6.49933039\'%3E%3C/polygon%3E%3C/svg%3E'); -} - -.markdown-preview-view .task-list-item.is-checked a { - filter: saturate(0.8) brightness(0.7); -} - -.cm-formatting-task { - font-family: var(--font-monospace); -} - -.nav-file, .nav-folder { - padding: 1px 2px; -} - -.nav-file-title, .nav-folder-title { - width: 100%; - cursor: default; - display: flex; - align-items: baseline; - flex-direction: row; - --text-normal: var(--text-muted); -} - -body:not(.is-grabbing) .nav-file .nav-file-title:hover:not(.is-active), body:not(.is-grabbing) .nav-folder .nav-folder-title:hover:not(.is-active) { - --background-secondary-alt: transparent; -} - -.nav-file .is-active { - --background-secondary-alt: var(--interactive-accent); - --text-normal: #ffffff; -} - -.nav-file-title-content, .nav-folder-title-content { - text-indent: 0; - white-space: nowrap; - text-overflow: ellipsis; - overflow: hidden; - display: block; -} - -.markdown-preview-view.is-readable-line-width .markdown-preview-section, .markdown-source-view.is-readable-line-width .CodeMirror { - max-width: 900px !important; - line-height: 26px; -} - -blockquote { - margin: 20px 0; - border-radius: 4px !important; -} - -body { - --font-monospace: 'Fira Code', 'Source Code Pro', monospace; -} - -mjx-container[jax='CHTML'] { - text-align: left; - outline: none; -} - -.math-block { - font-size: 1.25em; -} - -.cm-s-obsidian pre.HyperMD-codeblock, .cm-s-obsidian span.cm-inline-code, .cm-s-obsidian span.cm-math:not(.cm-formatting-math-begin):not(.cm-formatting-math-end), .markdown-preview-view code { - /* fix `` tag color */ - color: #98c379; -} - -.cm-s-obsidian span.cm-inline-code, .cm-s-obsidian span.cm-math, .cm-s-obsidian span.hmd-fold-math-placeholder { - /* fix tag size */ - font-weight: 100; - font-style: normal; -} - -.markdown-preview-view code { - vertical-align: 0; - word-break: break-word; -} - -.markdown-preview-section:not(:first-child) h1, .markdown-preview-section:not(:first-child) h2, .markdown-preview-section:not(:first-child) h3, .markdown-preview-section:not(:first-child) h4, .markdown-preview-section:not(:first-child) h5, .markdown-preview-section:not(:first-child) h6 { - margin-top: 40px !important; -} - -.markdown-preview-section h1, .markdown-preview-section h2, .markdown-preview-section h3, .markdown-preview-section h4, .markdown-preview-section h5, .markdown-preview-section h6 { - line-height: 1.2; -} - -h1, h2, h3, h4, h5, h6, strong, b, .view-header-title { - font-weight: 600; -} - -.workspace>.workspace-split>.workspace-leaf:first-of-type:last-of-type .view-header { - border: none; -} - -.status-bar, .side-dock.mod-right, .side-dock.mod-left { - border-color: var(--panel-border-color); - border-width: 1px; -} - -.status-bar { - --bar-vertical-padding: 4px; - --bar-height: calc(22px + (var(--bar-vertical-padding) * 2)); - line-height: 20px; - padding: 0 20px; - height: var(--bar-height); - max-height: var(--bar-height); - min-height: var(--bar-height); - overflow: hidden; -} - -.status-bar-item { - margin: auto 0; -} - -.status-bar-item>* { - padding-top: var(--bar-vertical-padding) !important; - padding-bottom: var(--bar-vertical-padding) !important; -} - -.side-dock-plugin-panel-inner { - padding-left: 6px; -} - -a, .markdown-preview-view .internal-link { - text-decoration: none; -} - -a:hover, .markdown-preview-view .internal-link:hover { - text-decoration: underline; -} - -.theme-dark :not(pre)>code[class*='language-'], .theme-dark pre[class*='language-'] { - background: var(--background-primary-alt); -} - -.theme-light :not(pre)>code[class*='language-'], .theme-light pre[class*='language-'] { - background: var(--background-primary); - box-shadow: inset 0 0 0 1px var(--background-primary-alt); - border-radius: 4px; -} - -.markdown-embed:not(.hover-popover .markdown-embed), .file-embed { - margin: 0; - border-radius: 4px; - margin: 0 !important; - margin-inline-start: 30px !important; - margin-inline-end: 30px !important; -} - -.markdown-embed { - border: 1px solid var(--background-modifier-border); - border-left-width: 5px; -} - -.markdown-embed .markdown-preview-view { - padding: 0 20px; -} - -.markdown-embed-link, .file-embed-link { - left: 8px; - right: unset; -} - -.theme-light .token.operator, .theme-light .token.entity, .theme-light .token.url, .theme-light .language-css .token.string, .theme-light .style .token.string { - background: transparent; -} - -/* Source: https://github.com/AGMStudio/prism-theme-one-dark */ - -code[class*='language-'], pre[class*='language-'] { - text-align: left !important; - white-space: pre !important; - word-spacing: normal !important; - word-break: normal !important; - word-wrap: normal !important; - line-height: 1.5 !important; - -moz-tab-size: 4 !important; - -o-tab-size: 4 !important; - tab-size: 4 !important; - -webkit-hyphens: none !important; - -moz-hyphens: none !important; - -ms-hyphens: none !important; - hyphens: none !important; -} - -/* Code blocks */ - -pre[class*='language-'] { - padding: 1em !important; - margin: .5em 0 !important; - overflow: auto !important; -} - -/* Inline code */ - -:not(pre)>code[class*='language-'] { - padding: .1em !important; - border-radius: .3em !important; - white-space: normal !important; -} - -.token.comment, .token.prolog, .token.doctype, .token.cdata { - color: var(--gray-1) !important; -} - -.token.punctuation { - color: var(--gray-2) !important; -} - -.token.selector, .token.tag { - color: var(--red) !important; -} - -.token.property, .token.boolean, .token.number, .token.constant, .token.symbol, .token.attr-name, .token.deleted { - color: var(--orange) !important; -} - -.token.string, .token.char, .token.attr-value, .token.builtin, .token.inserted { - color: var(--green) !important; -} - -.token.operator, .token.entity, .token.url, .language-css .token.string, .style .token.string { - color: var(--aqua) !important; -} - -.token.atrule, .token.keyword { - color: var(--purple) !important; -} - -.token.function, .token.macro.property { - color: var(--blue) !important; -} - -.token.class-name { - color: var(--yellow) !important; -} - -.token.regex, .token.important, .token.variable { - color: var(--purple) !important; -} - -.token.important, .token.bold { - font-weight: bold !important; -} - -.token.italic { - font-style: italic !important; -} - -.token.entity { - cursor: help !important; -} - -pre.line-numbers { - position: relative !important; - padding-left: 3.8em !important; - counter-reset: linenumber !important; -} - -pre.line-numbers>code { - position: relative !important; -} - -.line-numbers .line-numbers-rows { - position: absolute !important; - pointer-events: none !important; - top: 0 !important; - font-size: 100% !important; - left: -3.8em !important; - width: 3em !important; - /* works for line-numbers below 1000 lines */ - letter-spacing: -1px !important; - border-right: 0 !important; - -webkit-user-select: none !important; - -moz-user-select: none !important; - -ms-user-select: none !important; - user-select: none !important; -} - -.line-numbers-rows>span { - pointer-events: none !important; - display: block !important; - counter-increment: linenumber !important; -} - -.line-numbers-rows>span:before { - content: counter(linenumber) !important; - color: var(--syntax-gray-1) !important; - display: block !important; - padding-right: 0.8em !important; - text-align: right !important; -} diff --git a/OJ notes/pages/Leetcode Repeated-DNA-Sequences.md b/OJ notes/pages/Leetcode Repeated-DNA-Sequences.md new file mode 100644 index 0000000..c02ca40 --- /dev/null +++ b/OJ notes/pages/Leetcode Repeated-DNA-Sequences.md @@ -0,0 +1,103 @@ +# Leetcode Repeated-DNA-Sequences + +2022-09-06 19:58 + +> ##### Data structures: +> +> #DS #hash_table #string +> +> ##### Difficulty: +> +> #coding_problem #difficulty-medium +> +> ##### Additional tags: +> +> #leetcode +> +> ##### Revisions: +> +> N/A + +##### Links: + +- [Link to problem](https://leetcode.com/problems/repeated-dna-sequences/) + +--- + +### Problem + +The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. + +- For example, `"ACGAATTCCG"` is a **DNA sequence**. + +When studying **DNA**, it is useful to identify repeated sequences within the DNA. + +Given a string `s` that represents a **DNA sequence**, return all the **`10`-letter-long** sequences (substrings) that occur more than once in a DNA molecule. You may return the answer in **any order**. + +#### Examples + +**Example 1:** + +**Input:** s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT" +**Output:** ["AAAAACCCCC","CCCCCAAAAA"] + +**Example 2:** + +**Input:** s = "AAAAAAAAAAAAA" +**Output:** ["AAAAAAAAAA"] + +#### Constraints + +### Thoughts + +> [!summary] +> This is a #hash_table problem. + +The question ask for an answer, and the substrings can +overlap. So, using a map is prefered(Why?) + +Two reasons: +- Easy way to know if a array is a duplicate (set, map can + suffice.) +- Keep information on how many duplicates found, so we only + append it to the answer the first time we meet it. + +One trip-over hole: in the for loop, upper bound should be: +```cpp +for (int i = 0, top = s.size() - 9; i < top; i++) + ^^^ +``` + +Minus 9, because 9 is the extended length for an subarray starting with i. +``` +1234567890 +^ ^ +|--------| +i i+9 + +i + 9 - i + 1 = 10. +``` + +With these edge-cases taken care of, we can proceed to the +solution: + +### Solution + +```cpp +class Solution { +public: + vector findRepeatedDnaSequences(string s) { + unordered_map used; + vector ans = {}; + for (int i = 0, size = s.size() - 9; i < size; i++) { + string tmp = s.substr(i, 10); + + if ((used[tmp]++) == 1) { + ans.push_back(tmp); + } + } + + return ans; + } +}; +``` \ No newline at end of file