File size: 19,811 Bytes
7f8e190 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | {% extends "base.html" %}
{% import "_partials.html" as ui %}
{# Chrome, tab set, pane split, action bar and console follow two-sum-desktop /
two-sum-mobile. The right pane is a plain textarea editor, not a copy of the
source editor component. #}
{% block title %}{{ question.number }}. {{ question.title }} - LeetCode{% endblock %}
{% block main %}
<div class="wb">
<header class="wb-bar">
<div class="wb-bar__left">
{{ ui.logo(false) }}
<a class="wb-bar__list" href="/problemset/">
<span class="wb-bar__list-icon" aria-hidden="true"><svg viewBox="0 0 16 16" width="16" height="16" focusable="false"><path d="M2 4h12M2 8h12M2 12h8" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg></span>
<span class="wb-bar__list-text">Problem List</span>
</a>
<a class="wb-bar__step" href="/problems/{{ neighbours.previous }}/description/" aria-label="Prev Question">‹</a>
<a class="wb-bar__step" href="/problems/{{ neighbours.next }}/description/" aria-label="Next Question">›</a>
<a class="wb-bar__step" href="/problems/random/" aria-label="Pick one">
<svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true" focusable="false"><path d="M2 4h2.6l6.8 8H14M2 12h2.6l6.8-8H14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/><path d="m12 2.4 2 1.6-2 1.6M12 10.4l2 1.6-2 1.6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
</a>
</div>
<div class="wb-bar__center">
<button class="wb-run" type="submit" form="judge-form" name="action" value="run" data-run
{% if not member %}title="{{ auth_notice }}"{% endif %}>
<svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true" focusable="false"><path d="M5 3.4 12.4 8 5 12.6Z" fill="currentColor"/></svg>
<span class="visually-hidden">Run</span>
</button>
<button class="wb-submit" type="submit" form="judge-form" name="action" value="submit" data-submit
{% if not member %}title="{{ auth_notice }}"{% endif %}>
<svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true" focusable="false"><path d="M8 11V4.4M8 4.4 5.6 6.8M8 4.4l2.4 2.4" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M3.4 9.6a2.6 2.6 0 0 1 .9-5 3.9 3.9 0 0 1 7.5.6 2.4 2.4 0 0 1 .8 4.4" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/></svg>
Submit
</button>
</div>
<div class="wb-bar__right">
<span class="wb-bar__timer" data-stopwatch>00:00:00</span>
{% if member %}
<a class="wb-bar__member" href="/progress/">{{ member.username }}</a>
<form class="inline-form" method="post" action="/accounts/logout/">
<button class="wb-bar__link wb-bar__button" type="submit">Sign out</button>
</form>
{% else %}
<a class="wb-bar__link" href="/accounts/signup/">Register</a>
<span class="wb-bar__or" aria-hidden="true">or</span>
<a class="wb-bar__link" href="/accounts/login/">Log in</a>
{% endif %}
<a class="wb-bar__premium" href="/subscribe/">Premium</a>
</div>
</header>
<div class="wb-split">
<section class="wb-pane wb-pane--left" aria-label="Question">
<nav class="wb-tabs" aria-label="Question tabs">
{% for tab_id, tab_label in tabs %}
<a class="wb-tab wb-tab--{{ tab_id }}{% if tab_id == tab %} is-active{% endif %}"
href="/problems/{{ question.slug }}/{{ tab_id }}/{{ language_query }}">
<span class="wb-tab__icon" aria-hidden="true"></span>{{ tab_label }}
</a>
{% endfor %}
</nav>
<div class="wb-pane__scroll">
{% if tab == 'description' %}
<h1 class="wb-title">{{ question.number }}. {{ question.title }}</h1>
<div class="wb-chips">
<span class="pill pill--{{ question.difficulty|lower }}">{{ question.difficulty }}</span>
<details class="wb-chip">
<summary><span class="wb-chip__icon" aria-hidden="true"><svg viewBox="0 0 16 16" width="13" height="13" focusable="false"><path d="M2.5 8.6V3h5.6l5.4 5.4-5.6 5.6Z" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linejoin="round"/><circle cx="5.4" cy="5.6" r="1" fill="currentColor"/></svg></span>Topics</summary>
<ul class="wb-taglist">
{% for topic in question.topics %}
<li><a class="wb-tag" href="/problemset/?topic={{ topic|urlencode }}">{{ topic }}</a></li>
{% else %}
<li><span class="wb-tag wb-tag--muted">No topic tag</span></li>
{% endfor %}
</ul>
</details>
<span class="wb-chip wb-chip--locked" title="Company tags are a Premium feature">
<span class="wb-chip__icon" aria-hidden="true"><svg viewBox="0 0 12 12" width="11" height="11" focusable="false"><rect x="2" y="5" width="8" height="6" rx="1.4" fill="currentColor"/><path d="M4 5V3.6a2 2 0 0 1 4 0V5" fill="none" stroke="currentColor" stroke-width="1.3"/></svg></span>Companies
</span>
{% if question.hints %}
<details class="wb-chip">
<summary><span class="wb-chip__icon" aria-hidden="true"><svg viewBox="0 0 16 16" width="13" height="13" focusable="false"><path d="M6 12.4h4M6.6 14h2.8" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/><path d="M8 2a4 4 0 0 1 2.5 7.1c-.4.4-.6.8-.6 1.3H6.1c0-.5-.2-.9-.6-1.3A4 4 0 0 1 8 2Z" fill="none" stroke="currentColor" stroke-width="1.3"/></svg></span>Hint</summary>
<ol class="wb-hints">
{% for hint in question.hints %}
<li><span class="wb-hints__label">Hint {{ loop.index }}</span>{{ hint }}</li>
{% endfor %}
</ol>
</details>
{% endif %}
</div>
{% if question.workspace_ready %}
<div class="wb-statement">
<p>{{ question.summary }}</p>
{% for line in question.details %}
<p>{{ line }}</p>
{% endfor %}
{% for example in question.examples %}
<p class="wb-example__title"><strong>Example {{ loop.index }}:</strong></p>
<pre class="wb-example"><strong>Input:</strong> {{ example.input }}
<strong>Output:</strong> {{ example.output }}{% if example.explanation %}
<strong>Explanation:</strong> {{ example.explanation }}{% endif %}</pre>
{% endfor %}
{% if question.constraints %}
<p class="wb-statement__head"><strong>Constraints:</strong></p>
<ul class="wb-constraints">
{% for constraint in question.constraints %}
<li><code>{{ constraint }}</code></li>
{% endfor %}
</ul>
{% endif %}
{% if question.follow_up %}
<p class="wb-followup"><strong>Follow-up:</strong> {{ question.follow_up }}</p>
{% endif %}
</div>
{% else %}
<div class="wb-statement wb-statement--absent">
<p>{{ no_workspace_notice }}</p>
<p>The catalogue row for this question — its number, title, difficulty
and acceptance rate — comes from the captured problem-set page.
Its statement was not captured, and inventing one would not be an
honest reconstruction.</p>
<p><a href="/problems/two-sum/description/">Open 1. Two Sum</a>, the
question this clone reproduces in full.</p>
</div>
{% endif %}
{% if question.accepted_display %}
<dl class="wb-stats">
<div><dt>Accepted</dt><dd>{{ question.accepted_display }}/{{ question.submissions_display }}</dd></div>
<div><dt>Acceptance Rate</dt><dd>{{ '%.1f'|format(question.acceptance) }}%</dd></div>
</dl>
{% else %}
<dl class="wb-stats">
<div><dt>Acceptance Rate</dt><dd>{{ '%.1f'|format(question.acceptance) }}%</dd></div>
</dl>
{% endif %}
{% if similar %}
<section class="wb-similar">
<h2 class="wb-h2">Similar Questions</h2>
<ul>
{% for item in similar %}
<li>
{% if item.available %}
<a href="/problems/{{ item.slug }}/description/">{{ item.title }}</a>
{% else %}
<span class="wb-similar__plain" title="Not part of this offline catalogue">{{ item.title }}</span>
{% endif %}
<span class="wb-similar__difficulty wb-similar__difficulty--{{ item.difficulty|lower }}">{{ item.difficulty }}</span>
</li>
{% endfor %}
</ul>
</section>
{% endif %}
{# The captured page closes the Description tab with a Discussion
section: a heading carrying the thread count, a compose row, and the
site's own posting rules. The individual comments below it are
visitor-written content by named people and are not reproduced. #}
{% if question.discussion_display %}
<section class="wb-discussion">
<h2 class="wb-h2">Discussion ({{ question.discussion_display }})</h2>
<div class="wb-discussion__compose">
<span class="wb-discussion__type">Choose a type</span>
<span class="wb-discussion__field">Comment</span>
</div>
<div class="wb-discussion__rules">
<p class="wb-discussion__rules-title"><span aria-hidden="true">💡</span> Discussion Rules</p>
<ol>
<li>Please don’t post any solutions in this discussion.</li>
<li>The problem discussion is for asking questions about the problem or for sharing tips - anything except for solutions.</li>
<li>If you’d like to share your solution for feedback and ideas, please head to the solutions tab and post it there.</li>
</ol>
</div>
<p class="wb-muted">The captured thread is visitor-written content
attributed to named accounts, so this clone reproduces the section
and its rules but none of the posts.</p>
</section>
{% endif %}
{% elif tab == 'editorial' %}
<h1 class="wb-title">Editorial</h1>
{% if question.editorial_title %}
<h2 class="wb-h2">{{ question.editorial_title }}</h2>
{% for paragraph in question.editorial_body %}
<p>{{ paragraph }}</p>
{% endfor %}
{% for lang, code in question.editorial_code.items() %}
<h3 class="wb-h3">{{ lang|language_label }}</h3>
<pre class="wb-code">{{ code }}</pre>
{% endfor %}
<p class="wb-muted">This editorial was written for the offline clone. The
source editorial is behind a Premium subscription and was not captured.</p>
{% else %}
<p class="wb-muted">No editorial is reproduced for this question.</p>
{% endif %}
{% elif tab == 'solutions' %}
<h1 class="wb-title">Solutions</h1>
{% if question.community_solutions %}
<ul class="wb-solutions">
{% for entry in question.community_solutions %}
<li>
<p class="wb-solutions__title">{{ entry.title }}</p>
<p class="wb-solutions__meta">{{ entry.author }} · {{ entry.language }} · {{ entry.votes }} votes</p>
</li>
{% endfor %}
</ul>
<p class="wb-muted">These entries are local fixture data. The source
community solutions were not captured.</p>
{% else %}
<p class="wb-muted">No community solution is reproduced for this question.</p>
{% endif %}
{% else %}
<h1 class="wb-title">Submissions</h1>
{% if member %}
{% if question_submissions %}
<table class="wb-submissions">
<thead>
<tr><th scope="col">Status</th><th scope="col">Language</th><th scope="col">Runtime</th><th scope="col">Memory</th><th scope="col">Submitted</th></tr>
</thead>
<tbody>
{% for entry in question_submissions %}
<tr>
<td><span class="verdict verdict--{{ entry.status|lower|replace(' ', '-') }}">{{ entry.status }}</span></td>
<td>{{ entry.language|language_label }}</td>
<td>{% if entry.runtime_ms is not none %}{{ entry.runtime_ms }} ms{% else %}N/A{% endif %}</td>
<td>{% if entry.memory_mb is not none %}{{ entry.memory_mb }} MB{% else %}N/A{% endif %}</td>
<td>{{ entry.created_at }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="wb-muted">You have not submitted a solution to this question yet.</p>
{% endif %}
{% else %}
<p class="wb-muted">You need to <a href="/accounts/login/?next={{ next_path|urlencode }}">log in</a> to see your submissions.</p>
{% endif %}
{% endif %}
</div>
<footer class="wb-actions">
<button class="wb-actions__button" type="button" data-vote="up">
<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" focusable="false"><path d="M5.6 13.6V6.8l3-4.4 1 .5-.7 3.3h3.7l-1.4 7.4Z" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linejoin="round"/><rect x="2.4" y="6.8" width="2.6" height="6.8" rx="0.8" fill="none" stroke="currentColor" stroke-width="1.3"/></svg>
{{ question.likes_display or '0' }}
</button>
<button class="wb-actions__button" type="button" data-vote="down" aria-label="Dislike">
<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" focusable="false"><path d="M10.4 2.4v6.8l-3 4.4-1-.5.7-3.3H3.4l1.4-7.4Z" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linejoin="round"/><rect x="11" y="2.4" width="2.6" height="6.8" rx="0.8" fill="none" stroke="currentColor" stroke-width="1.3"/></svg>
</button>
<a class="wb-actions__button" href="/problems/{{ question.slug }}/solutions/">
<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" focusable="false"><path d="M2.6 3.4h10.8v7.2H8.4L5.2 13.2v-2.6H2.6Z" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linejoin="round"/></svg>
{{ question.discussion_display or '0' }}
</a>
<button class="wb-actions__button" type="button" data-star aria-label="Add to list">
<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" focusable="false"><path d="m8 2.4 1.7 3.6 3.9.5-2.9 2.7.8 3.9L8 11.2 4.5 13.1l.8-3.9-2.9-2.7 3.9-.5Z" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linejoin="round"/></svg>
</button>
</footer>
</section>
<section class="wb-pane wb-pane--right" aria-label="Code">
<form id="judge-form" class="wb-editor" method="post" action="/problems/{{ question.slug }}/judge">
<div class="wb-editor__head">
<span class="wb-editor__label"><span class="wb-editor__glyph" aria-hidden="true"></></span> Code</span>
</div>
<div class="wb-editor__bar">
<label class="wb-editor__lang">
<span class="visually-hidden">Language</span>
<select name="language" data-language>
{% for lang in question.languages %}
<option value="{{ lang }}"{% if lang == language %} selected{% endif %}>{{ lang|language_label }}</option>
{% else %}
<option value="python3" selected>Python3</option>
{% endfor %}
</select>
</label>
<span class="wb-editor__auto"><span class="wb-editor__dot" aria-hidden="true"></span>Auto</span>
</div>
<div class="wb-editor__body">
<pre class="wb-gutter" aria-hidden="true" data-gutter>1</pre>
<textarea class="wb-code-input" name="source" spellcheck="false" autocomplete="off"
aria-label="Code editor" data-editor>{{ source }}</textarea>
</div>
<div class="wb-editor__status">
<span data-saved-state>{{ saved_label }}</span>
<span data-cursor>Ln 1, Col 1</span>
</div>
{% if not member %}
<p class="wb-notice" data-auth-notice>
{{ auth_notice|replace('log in / sign up', '') }}
<a href="/accounts/login/?next={{ next_path|urlencode }}">log in / sign up</a> to run or submit
</p>
{% endif %}
<div class="wb-console">
<nav class="wb-console__tabs" aria-label="Console tabs">
<button class="wb-console__tab{% if console_tab == 'testcase' %} is-active{% endif %}" type="button" data-console-tab="testcase">
<span class="wb-console__icon wb-console__icon--case" aria-hidden="true"></span>Testcase
</button>
<button class="wb-console__tab{% if console_tab == 'result' %} is-active{% endif %}" type="button" data-console-tab="result">
<span class="wb-console__icon wb-console__icon--result" aria-hidden="true"></span>Test Result
</button>
</nav>
<div class="wb-console__panel{% if console_tab != 'testcase' %} is-hidden{% endif %}" data-console-panel="testcase">
{% if cases %}
<div class="wb-cases" role="tablist" aria-label="Test cases">
{% for case in cases %}
<button class="wb-case{% if loop.first %} is-active{% endif %}" type="button" role="tab"
aria-selected="{{ 'true' if loop.first else 'false' }}" data-case-tab="{{ loop.index0 }}">Case {{ loop.index }}</button>
{% endfor %}
</div>
<input type="hidden" name="case_count" value="{{ cases|length }}">
<input type="hidden" name="case_arity" value="{{ question.case_labels|length }}">
{% for case in cases %}
<div class="wb-case-input{% if not loop.first %} is-hidden{% endif %}" data-case-panel="{{ loop.index0 }}">
{% if question.case_labels %}
{# The source shows one labelled field per parameter. #}
{% for label in question.case_labels %}
<label class="wb-case-field">
<span class="wb-case-field__label">{{ label }} =</span>
<textarea name="case_line" rows="1" spellcheck="false"
{% if not supports_custom_input %}readonly{% endif %}>{{ case.splitlines()[loop.index0] if case.splitlines()|length > loop.index0 else '' }}</textarea>
</label>
{% endfor %}
{% else %}
<label class="wb-case-field wb-case-field--plain">
<span class="visually-hidden">Case {{ loop.index }} input</span>
<textarea name="case_line" rows="{{ case.splitlines()|length or 1 }}" spellcheck="false"
{% if not supports_custom_input %}readonly{% endif %}>{{ case }}</textarea>
</label>
{% endif %}
</div>
{% endfor %}
{% if not supports_custom_input %}
<p class="wb-muted">This question runs against its own fixed data set.</p>
{% endif %}
{% else %}
<p class="wb-muted">No test case is reproduced for this question.</p>
{% endif %}
</div>
<div class="wb-console__panel{% if console_tab != 'result' %} is-hidden{% endif %}" data-console-panel="result" data-result-panel>
{% include "_result.html" %}
</div>
</div>
</form>
</section>
</div>
</div>
{% endblock %}
{% block scripts %}<script src="/static/js/workbench.js" defer></script>{% endblock %}
|