Skip to content

ryderfang/Algo-Swift

Repository files navigation

Algo-Swift

Swift

This repo is about algorithm codes writing by Swift. Two parts included.

🗝 Solutions

My solutions of LeetCode problems with Swift.

⏳ Progress

LeetCode Stats

Motivation comes from incentive.

  • 🔸 Lv.1 "100 easy" 🎯🎉
  • 🔹 Lv.10 "200 easy" 🎯🎉
  • 🔶 Lv.20 [🥉] "400 easy"
  • 🔷 Lv.30 "AK easy"
  • 🟢 Lv.40 "100 medium" 🎯🎉
  • 🟠 Lv.50 [🥈] "200 medium" 🎯🎉
  • 🔵 Lv.60 "400 medium 🚶🚶🚶
  • 🟣 Lv.70 "600 medium"
  • 🟩 Lv.80 "100 hard"
  • 🟧 Lv.90 [🥇] "200 hard"
  • 🟦 Lv.100 "300 hard"
  • 🟪 Lv.110 "AK medium"
  • 🔱 Lv.120 [🏆] "AK hard"

📦 Base

📔 Templetes

While solving problems I summarize those code snippets as templates. Thanks to references:

‼️ VSCode-LeetCode extension

To fix redeclaration of 'Solution' issue, I modified the extension.

  • path: ~/.vscode/extensions/leetcode.vscode-leetcode-0.18.1
  1. add Custom Flags to Build Settings of Xcode project

  1. change template
  • node_modules/vsc-leetcode-cli/templates/codeonly.tpl
// codeonly.tpl
${comment.start}
${comment.line} @lc app=${app} id=${fid} lang=${lang}
${comment.line}
${comment.line} [${fid}] ${name}
${comment.end}

${comment.singleLine} @lc code=start
#if !LC_SOLUTION_EXT
class Solution {}
#endif

${code}
${comment.singleLine} @lc code=end
  1. change js logic
  • node_modules/vsc-leetcode-cli/lib/core.js
core.exportProblem = function(problem, opts) {
  const data = _.extend({}, problem);
  // ... 
  data.code = (opts.code || data.code || '').replace(/\r\n/g, '\n');
  data.comment = h.langToCommentStyle(data.lang);
  data.percent = data.percent.toFixed(2);
  data.testcase = util.inspect(data.testcase || '');

  // fix 'swift' redeclaration issue
  data.code = data.code.replace(/class Solution/g, 'extension Solution');

  // ...
  return file.render(opts.tpl, data);
};

📚 Books

I bought several books about algorithm years ago, mostly writen by Liu Rujia (as known as @srbga).

Of course never finished reading them :(

Now I'm going to rewrite codes in these books with Swift.

Let's Go! 🖖

About

Algorithms with Swift | LeetCode | Contest

Topics

Resources

Stars

Watchers

Forks