[
  {
    "path": ".gitignore",
    "content": ".idea/\n.DS_Store\n\n# Binaries for programs and plugins\n*.exe\n*.dll\n*.so\n*.dylib\n\n# Test binary, build with `go test -c`\n*.test\n\n# Output of the go coverage tool, specifically when used with LiteIDE\n*.out\n\n# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736\n.glide/\n"
  },
  {
    "path": "LICENSE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "## mygo\n\n> 此项目建议搭配[Code tree for GitHub](https://github.com/buunguyen/octotree)效果更佳。\n> \n> ##### 环境\n> \n> go1.10 darwin/amd64\n\n### Leetcode\n\n使用 Go 解答 Leetcode 题目。[链接](/algorithm/leetcode)\n\n| 题号  | 题目   | 难度  |\n|:---:|:---- |:---:|\n| 1   | [两数之和](algorithm/leetcode/001) | 简单  |\n| 7   | [反转整数](algorithm/leetcode/007) | 简单  |\n| 9   | [回文数](algorithm/leetcode/009) | 简单  |\n| 13   | [罗马数字转整数](algorithm/leetcode/013) | 简单  |\n| 14   | [最长公共前缀](algorithm/leetcode/014) | 简单  |\n| 20   | [有效的括号](algorithm/leetcode/020) | 简单  |\n| 21   | [合并两个有序链表](algorithm/leetcode/021) | 简单  |\n| 26   | [删除排序数组中的重复项](algorithm/leetcode/026) | 简单  |\n| 27   | [移除元素](algorithm/leetcode/027) | 简单  |\n| 28   | [实现strStr()](algorithm/leetcode/028) | 简单  |\n| 35   | [搜索插入位置](algorithm/leetcode/035) | 简单  |\n| 38   | [报数](algorithm/leetcode/038) | 简单  |\n| 53   | [最大子序和](algorithm/leetcode/053) | 简单  |\n| 58   | [最后一个单词的长度](algorithm/leetcode/058) | 简单  |\n| 66   | [加一](algorithm/leetcode/066) | 简单  |\n| 67   | [二进制求和](algorithm/leetcode/067) | 简单  |\n| 69   | [x 的平方根](algorithm/leetcode/069) | 简单  |\n| 70   | [爬楼梯](algorithm/leetcode/070) | 简单  |\n| 83   | [删除排序链表中的重复元素](algorithm/leetcode/083) | 简单  |\n| 88   | [合并两个有序数组](algorithm/leetcode/088) | 简单  |\n| 100   | [相同的树](algorithm/leetcode/100) | 简单  |\n| 101   | [对称二叉树](algorithm/leetcode/101) | 简单  |\n| 104   | [二叉树的最大深度](algorithm/leetcode/104) | 简单  |\n| 107   | [二叉树的层次遍历 II](algorithm/leetcode/107) | 简单  |\n| 108   | [将有序数组转换为二叉搜索树 ](algorithm/leetcode/108) | 简单  |\n| 110   | [平衡二叉树](algorithm/leetcode/110) | 简单  |\n| 111   | [二叉树的最小深度](algorithm/leetcode/111) | 简单  |\n| 112   | [路径总和](algorithm/leetcode/112) | 简单  |\n| 118   | [杨辉三角](algorithm/leetcode/118) | 简单  |\n| 119   | [杨辉三角 II](algorithm/leetcode/119) | 简单  |\n| 121   | [买卖股票的最佳时机](algorithm/leetcode/121) | 简单  |\n| 122   | [买卖股票的最佳时机 II](algorithm/leetcode/122) | 简单  |\n| 125   | [验证回文串](algorithm/leetcode/125) | 简单  |\n| 136   | [只出现一次的数字](algorithm/leetcode/136) | 简单  |\n| 167   | [两数之和 II - 输入有序数组](algorithm/leetcode/167) | 简单  |\n| 168   | [Excel表列名称](algorithm/leetcode/168) | 简单  |\n| 169   | [求众数](algorithm/leetcode/169) | 简单  |\n| 171   | [Excel表列序号](algorithm/leetcode/171) | 简单  |\n| 172   | [阶乘后的零](algorithm/leetcode/172) | 简单  |\n| 189   | [旋转数组](algorithm/leetcode/189) | 简单  |\n| 198   | [打家劫舍](algorithm/leetcode/198) | 简单  |\n| 202   | [快乐数](algorithm/leetcode/202) | 简单  |\n| 203   | [删除链表中的节点](algorithm/leetcode/203) | 简单  |\n| 204   | [计数质数](algorithm/leetcode/204) | 简单  |\n| 205   | [同构字符串](algorithm/leetcode/205) | 简单  |\n| 206   | [反转链表](algorithm/leetcode/206) | 简单  |\n| 217   | [存在重复元素](algorithm/leetcode/217) | 简单  |\n| 219   | [存在重复元素 II](algorithm/leetcode/219) | 简单  |\n| 226   | [翻转二叉树](algorithm/leetcode/226) | 简单  |\n| 231   | [2的幂](algorithm/leetcode/231) | 简单  |\n| 234   | [回文链表](algorithm/leetcode/234) | 简单  |\n| 258   | [各位相加](algorithm/leetcode/258) | 简单  |\n| 263   | [丑数](algorithm/leetcode/263) | 简单  |\n| 268   | [缺失数字](algorithm/leetcode/268) | 简单  |\n| 283   | [移动零](algorithm/leetcode/283) | 简单  |\n| 290   | [单词模式](algorithm/leetcode/290) | 简单  |\n| 292   | [Nim游戏](algorithm/leetcode/292) | 简单  |\n| 303   | [区域和检索 - 不可变](algorithm/leetcode/303) | 简单  |\n| 326   | [3的幂](algorithm/leetcode/326) | 简单  |\n| 342   | [4的幂](algorithm/leetcode/342) | 简单  |\n| 344   | [反转字符串](algorithm/leetcode/344) | 简单  |\n| 345   | [反转字符串中的元音字母](algorithm/leetcode/345) | 简单  |\n| 349   | [两个数组的交集](algorithm/leetcode/349) | 简单  |\n| 350   | [两个数组的交集 II](algorithm/leetcode/350) | 简单  |\n| 367   | [有效的完全平方数](algorithm/leetcode/367) | 简单  |\n| 371   | [两整数之和](algorithm/leetcode/371) | 简单  |\n| 383   | [赎金信](algorithm/leetcode/383) | 简单  |\n| 387   | [字符串中的第一个唯一字符](algorithm/leetcode/387) | 简单  |\n| 389   | [找不同](algorithm/leetcode/389) | 简单  |\n| 400   | [第N个数字](algorithm/leetcode/400) | 简单  |\n| 404   | [左叶子之和](algorithm/leetcode/404) | 简单  |\n| 405   | [数字转换为十六进制数](algorithm/leetcode/405) | 简单  |\n| 409   | [最长回文串](algorithm/leetcode/409) | 简单  |\n| 412   | [Fizz Buzz](algorithm/leetcode/412) | 简单  |\n| 414   | [第三大的数](algorithm/leetcode/414) | 简单  |\n| 415   | [字符串相加](algorithm/leetcode/415) | 简单  |\n| 434   | [字符串中的单词数](algorithm/leetcode/434) | 简单  |\n| 437   | [路径总和 III](algorithm/leetcode/437) | 简单  |\n| 438   | [找到字符串中所有字母异位词](algorithm/leetcode/438) | 简单  |\n| 441   | [排列硬币](algorithm/leetcode/441) | 简单  |\n| 443   | [压缩字符串](algorithm/leetcode/443) | 简单  |\n| 447   | [回旋镖的数量](algorithm/leetcode/447) | 简单  |\n| 448   | [找到所有数组中消失的数字](algorithm/leetcode/448) | 简单  |\n| 453   | [最小移动次数使数组元素相等](algorithm/leetcode/453) | 简单  |\n| 455   | [分发饼干](algorithm/leetcode/455) | 简单  |\n| 459   | [重复的子字符串](algorithm/leetcode/459) | 简单  |\n| 461   | [汉明距离](algorithm/leetcode/461) | 简单  |\n| 463   | [岛屿的周长](algorithm/leetcode/463) | 简单  |\n| 475   | [供暖器](algorithm/leetcode/475) | 简单  |\n| 476   | [数字的补数](algorithm/leetcode/476) | 简单  |\n| 479   | [最大回文数乘积](algorithm/leetcode/479) | 简单  |\n| 485   | [最大连续1的个数](algorithm/leetcode/485) | 简单  |\n| 492   | [构造矩形](algorithm/leetcode/492) | 简单  |\n| 496   | [下一个更大元素 I](algorithm/leetcode/496) | 简单  |\n| 500   | [键盘行](algorithm/leetcode/500) | 简单  |\n| 501   | [Find Mode in Binary Search Tree](algorithm/leetcode/501) | 简单  |\n| 504   | [七进制数](algorithm/leetcode/504) | 简单  |\n| 506   | [相对名次](algorithm/leetcode/506) | 简单  |\n| 507   | [完美数](algorithm/leetcode/507) | 简单  |\n| 520   | [检测大写字母](algorithm/leetcode/520) | 简单  |\n| 521   | [最长特殊序列 Ⅰ](algorithm/leetcode/521) | 简单  |\n| 530   | [二叉搜索树的最小绝对差](algorithm/leetcode/530) | 简单  |\n| 532   | [数组中的K-diff数对](algorithm/leetcode/532) | 简单  |\n| 538   | [把二叉搜索树转换为累加树](algorithm/leetcode/538) | 简单  |\n| 541   | [反转字符串 II](algorithm/leetcode/541) | 简单  |\n| 543   | [二叉树的直径](algorithm/leetcode/543) | 简单  |\n| 551   | [学生出勤纪录 I](algorithm/leetcode/551) | 简单  |\n| 557   | [反转字符串中的单词 III](algorithm/leetcode/557) | 简单  |\n| 561   | [数组拆分 I](algorithm/leetcode/561) | 简单  |\n| 563   | [二叉树的坡度](algorithm/leetcode/563) | 简单  |\n| 566   | [重塑矩阵](algorithm/leetcode/566) | 简单  |\n| 572   | [另一个树的子树](algorithm/leetcode/572) | 简单  |\n| 575   | [分糖果](algorithm/leetcode/575) | 简单  |\n| 581   | [最短无序连续子数组](algorithm/leetcode/581) | 简单  |\n| 594   | [最长和谐子序列](algorithm/leetcode/594) | 简单  |\n| 598   | [范围求和 II](algorithm/leetcode/598) | 简单  |\n| 599   | [两个列表的最小索引总和](algorithm/leetcode/599) | 简单  |\n| 605   | [种花问题](algorithm/leetcode/605) | 简单  |\n| 606   | [根据二叉树创建字符串](algorithm/leetcode/606) | 简单  |\n| 617   | [合并二叉树](algorithm/leetcode/617) | 简单  |\n| 628   | [三个数的最大乘积](algorithm/leetcode/628) | 简单  |\n| 633   | [平方数之和](algorithm/leetcode/633) | 简单  |\n| 637   | [二叉树的层平均值](algorithm/leetcode/637) | 简单  |\n| 643   | [子数组最大平均数 I](algorithm/leetcode/643) | 简单  |\n| 645   | [错误的集合](algorithm/leetcode/645) | 简单  |\n| 653   | [两数之和 IV - 输入 BST](algorithm/leetcode/653) | 简单  |\n| 657   | [判断路线成圈](algorithm/leetcode/657) | 简单  |\n| 661   | [图片平滑器](algorithm/leetcode/661) | 简单  |\n| 669   | [修剪二叉搜索树](algorithm/leetcode/669) | 简单  |\n| 674   | [最长连续递增序列](algorithm/leetcode/674) | 简单  |\n| 682   | [棒球比赛](algorithm/leetcode/682) | 简单  |\n| 686   | [重复叠加字符串匹配](algorithm/leetcode/686) | 简单  |\n| 687   | [最长同值路径](algorithm/leetcode/687) | 简单  |\n| 693   | [交替位二进制数](algorithm/leetcode/693) | 简单  |\n| 695   | [岛屿的最大面积](algorithm/leetcode/695) | 简单  |\n| 696   | [计数二进制子串](algorithm/leetcode/696) | 简单  |\n| 697   | [数组的度](algorithm/leetcode/697) | 简单  |\n| 717   | [1比特与2比特字符](algorithm/leetcode/717) | 简单  |\n| 724   | [寻找数组的中心索引](algorithm/leetcode/724) | 简单  |\n| 728   | [自除数](algorithm/leetcode/728) | 简单  |\n| 744   | [寻找比目标字母大的最小字母](algorithm/leetcode/744) | 简单  |\n| 746   | [使用最小花费爬楼梯](algorithm/leetcode/746) | 简单  |\n| 747   | [至少是其他数字两倍的最大数](algorithm/leetcode/747) | 简单  |\n| 762   | [二进制表示中质数个计算置位](algorithm/leetcode/762) | 简单  |\n| 766   | [托普利茨矩阵](algorithm/leetcode/766) | 简单  |\n| 771   | [宝石与石头](algorithm/leetcode/771) | 简单  |\n| 783   | [二叉搜索树结点最小距离](algorithm/leetcode/783) | 简单  |\n| 784   | [字母大小写全排列](algorithm/leetcode/784) | 简单  |\n| 788   | [旋转数字](algorithm/leetcode/788) | 简单  |\n| 796   | [旋转字符串](algorithm/leetcode/796) | 简单  |\n| 804   | [唯一摩尔斯密码词](algorithm/leetcode/804) | 简单  |\n| 811   | [子域名访问计数](algorithm/leetcode/811) | 简单  |\n| 812   | [最大三角形面积](algorithm/leetcode/812) | 简单  |\n| 821   | [字符的最短距离](algorithm/leetcode/821) | 简单  |\n| 824   | [山羊拉丁文](algorithm/leetcode/824) | 简单  |\n| 829   | [连续整数求和](algorithm/leetcode/829) | 中等  |\n| 830   | [较大分组的位置](algorithm/leetcode/830) | 简单  |\n| 832   | [翻转图像](algorithm/leetcode/832) | 简单  |\n| 836   | [矩形重叠](algorithm/leetcode/836) | 简单  |\n| 840   | [矩阵中的幻方](algorithm/leetcode/840) | 简单  |\n| 844   | [比较含退格的字符串](algorithm/leetcode/844) | 简单  |\n\n\n### 剑指offer(第二版)\n\n使用 Go 解答 剑指offer 题目。[链接](/algorithm/sfo)\n\n### Go 语言笔记\n\n学习 Go 语言过程中做的笔记。[链接](/notes)\n"
  },
  {
    "path": "algorithm/leetcode/001/ac001.go",
    "content": "package problem001\n\nfunc twoSum(nums []int, target int) []int {\n\t// m 负责保存map[整数]整数的序列号\n\tm := make(map[int]int, len(nums))\n\n\t// 通过 for 循环，获取b的序列号\n\tfor i, b := range nums {\n\t\t// 通过查询map，获取a = target - b的序列号\n\t\tif j, ok := m[target-b]; ok {\n\t\t\t// ok 为 true\n\t\t\t// 说明在i之前，存在nums[j] == a\n\t\t\treturn []int{j, i}\n\t\t\t// 注意，顺序是j，i，因为j<i\n\t\t}\n\n\t\t// 把序号i和i对应的值，存入map\n\t\tm[nums[i]] = i\n\t}\n\n\treturn nil\n}\n"
  },
  {
    "path": "algorithm/leetcode/001/ac001_test.go",
    "content": "package problem001\n\nimport (\n\t\"testing\"\n\t\"github.com/stretchr/testify/assert\"\n)\n\ntype argument struct {\n\tnumberArray []int\n\ttarget      int\n}\n\ntype answer struct {\n\tnumberArray []int\n}\n\ntype example struct {\n\targ argument\n\tans answer\n}\n\nfunc TestOk(t *testing.T) {\n\texamples := []example{\n\t\t{\n\t\t\targ: argument{\n\t\t\t\tnumberArray: []int{3, 2, 4},\n\t\t\t\ttarget:      6,\n\t\t\t},\n\t\t\tans: answer{\n\t\t\t\tnumberArray: []int{1, 2},\n\t\t\t},\n\t\t}, {\n\t\t\targ: argument{\n\t\t\t\tnumberArray: []int{3, 2, 4},\n\t\t\t\ttarget:      8,\n\t\t\t},\n\t\t\tans: answer{\n\t\t\t\tnumberArray: nil,\n\t\t\t},\n\t\t},\n\t}\n\n\tast := assert.New(t)\n\tfor _, exam := range examples {\n\t\targ, ans := exam.arg, exam.ans\n\t\tast.Equal(ans.numberArray, twoSum(arg.numberArray, arg.target),\n\t\t\t\"%v %v\", arg.numberArray, arg.target)\n\t}\n\n}\n"
  },
  {
    "path": "algorithm/leetcode/007/ac007.go",
    "content": "package problem007\n\nimport \"math\"\n\nfunc reverse(x int) int {\n\tvar result int64\n\tfor 0 != x {\n\t\tresult = result*10 + int64(x%10)\n\t\tx /= 10\n\t}\n\n\tif result > math.MaxInt32 || result < math.MinInt32 {\n\t\treturn 0\n\t}\n\treturn int(result)\n}\n"
  },
  {
    "path": "algorithm/leetcode/007/ac007_test.go",
    "content": "package problem007\n\nimport (\n\t\"testing\"\n\t\"github.com/stretchr/testify/assert\"\n)\n\ntype argument struct {\n\tnumber int\n}\n\ntype answer struct {\n\trevertNumber int\n}\n\ntype example struct {\n\targ argument\n\tans answer\n}\n\nfunc Test_reverse(t *testing.T) {\n\texamples := []example{\n\t\t{\n\t\t\targ: argument{\n\t\t\t\tnumber: 1230,\n\t\t\t},\n\t\t\tans: answer{\n\t\t\t\trevertNumber: 321,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\targ: argument{\n\t\t\t\tnumber: -123,\n\t\t\t},\n\t\t\tans: answer{\n\t\t\t\trevertNumber: -321,\n\t\t\t},\n\t\t},\n\t}\n\n\tast := assert.New(t)\n\tfor _, exam := range examples {\n\t\tans, arg := exam.ans, exam.arg\n\t\tast.Equal(ans.revertNumber, reverse(arg.number),\n\t\t\t\"%v %v\", arg.number, ans.revertNumber)\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/009/ac009.go",
    "content": "package problem009\n\n// 负数不是回文的\nfunc isPalindrome(x int) bool {\n\tif 0 > x || (0 == x%10 && 0 != x) {\n\t\treturn false\n\t}\n\n\tvar revertedNumber int\n\tfor x > revertedNumber {\n\t\trevertedNumber = revertedNumber*10 + x%10\n\t\tx /= 10\n\t}\n\n\treturn (x == revertedNumber) || (x == revertedNumber/10)\n}\n"
  },
  {
    "path": "algorithm/leetcode/009/ac009_test.go",
    "content": "package problem009\n\nimport (\n\t\"testing\"\n\t\"github.com/stretchr/testify/assert\"\n)\n\nfunc Test_isPalindrome(t *testing.T) {\n\ttype argument struct {\n\t\tx int\n\t}\n\ttype example struct {\n\t\targ argument\n\t\tans bool\n\t}\n\n\texamples := []example{\n\t\t{\n\t\t\targ: argument{\n\t\t\t\tx: 12321,\n\t\t\t},\n\t\t\tans: true,\n\t\t},\n\t\t{\n\t\t\targ: argument{\n\t\t\t\tx: 12344321,\n\t\t\t},\n\t\t\tans: true,\n\t\t},\n\t\t{\n\t\t\targ: argument{\n\t\t\t\tx: 98765,\n\t\t\t},\n\t\t\tans: false,\n\t\t},\n\t}\n\n\tast := assert.New(t)\n\tfor _, exam := range examples {\n\t\tans, arg := exam.ans, exam.arg\n\t\tast.Equal(ans, isPalindrome(arg.x),\n\t\t\t\"%v %v\", arg.x, ans)\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/013/ac013.go",
    "content": "package problem013\n\nfunc romanToInt(s string) int {\n\troman := map[byte]int{\n\t\t'I': 1,\n\t\t'V': 5,\n\t\t'X': 10,\n\t\t'L': 50,\n\t\t'C': 100,\n\t\t'D': 500,\n\t\t'M': 1000,\n\t}\n\n\tif len(s) <= 0 {\n\t\treturn 0\n\t}\n\t// 当 map 中不存在该键时 ok 为 false\n\tsum, ok := roman[s[len(s)-1]]\n\tif !ok {\n\t\treturn 0\n\t}\n\n\tfor i := len(s) - 2; i >= 0; i-- {\n\t\tif roman[s[i]] < roman[s[i+1]] {\n\t\t\tsum -= roman[s[i]]\n\t\t} else {\n\t\t\tsum += roman[s[i]]\n\t\t}\n\t}\n\treturn sum\n}\n"
  },
  {
    "path": "algorithm/leetcode/013/ac013_test.go",
    "content": "package problem013\n\nimport (\n\t\"testing\"\n\t\"github.com/stretchr/testify/assert\"\n)\n\nfunc Test_romanToInt(t *testing.T) {\n\ttype argument struct {\n\t\tstr string\n\t}\n\ttype example struct {\n\t\targ argument\n\t\tans int\n\t}\n\n\texamples := []example{\n\t\t{\n\t\t\targ: argument{\n\t\t\t\tstr: \"VIII\",\n\t\t\t},\n\t\t\tans: 8,\n\t\t},\n\t\t{\n\t\t\targ: argument{\n\t\t\t\tstr: \"IV\",\n\t\t\t},\n\t\t\tans: 4,\n\t\t},\n\t}\n\n\tast := assert.New(t)\n\tfor _, exam := range examples {\n\t\tans, arg := exam.ans, exam.arg\n\t\tast.Equal(ans, romanToInt(arg.str),\n\t\t\t\"%v %v\", arg.str, ans)\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/014/ac014.go",
    "content": "package problem014\n\nimport (\n\t\"sort\"\n)\n\nfunc longestCommonPrefix(strs []string) string {\n\tif nil == strs || 0 >= len(strs) {\n\t\treturn \"\"\n\t}\n\tsort.Strings(strs)\n\n\tfirst := strs[0]\n\tlast := strs[len(strs)-1]\n\tvar i, length int\n\tif len(first) < len(last) {\n\t\tlength = len(first)\n\t} else {\n\t\tlength = len(last)\n\t}\n\n\tfor i < length && first[i] == last[i] {\n\t\ti++\n\t}\n\treturn first[0:i]\n}\n"
  },
  {
    "path": "algorithm/leetcode/014/ac014_test.go",
    "content": "package problem014\n\nimport (\n\t\"testing\"\n\t\"github.com/stretchr/testify/assert\"\n)\n\nfunc Test_longestCommonPrefix(t *testing.T) {\n\ttype argument struct {\n\t\tstrs []string\n\t}\n\ttype example struct {\n\t\targ argument\n\t\tans string\n\t}\n\texamples := []example{\n\t\t{\n\t\t\targ: argument{\n\t\t\t\tstrs: []string{\"abcd\", \"abc\", \"ab\"},\n\t\t\t},\n\t\t\tans: \"ab\",\n\t\t},\n\t}\n\n\tast := assert.New(t)\n\tfor _, exam := range examples {\n\t\tans, arg := exam.ans, exam.arg\n\t\tast.Equal(ans, longestCommonPrefix(arg.strs),\n\t\t\t\"%v %v\", arg.strs, ans)\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/020/ac020.go",
    "content": "package problem020\n\nimport \"github.com/emirpasic/gods/stacks/arraystack\"\n\nfunc isValid(s string) bool {\n\tstack := arraystack.New()\n\tfor _, c := range s {\n\t\tif c == '(' {\n\t\t\tstack.Push(')')\n\t\t} else if c == '[' {\n\t\t\tstack.Push(']')\n\t\t} else if c == '{' {\n\t\t\tstack.Push('}')\n\t\t} else {\n\t\t\tif stack.Empty() {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\ttempC, _ := stack.Pop()\n\t\t\tif tempC != c {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t}\n\treturn stack.Empty()\n}\n"
  },
  {
    "path": "algorithm/leetcode/020/ac020_test.go",
    "content": "package problem020\n\nimport (\n\t\"testing\"\n\t\"github.com/stretchr/testify/assert\"\n)\n\nfunc Test_isValid(t *testing.T) {\n\ttype argument struct {\n\t\ts string\n\t}\n\ttype example struct {\n\t\targ argument\n\t\tans bool\n\t}\n\texamples := []example{\n\t\t{\n\t\t\targ: argument{\n\t\t\t\ts: \"{[()]}\",\n\t\t\t},\n\t\t\tans: true,\n\t\t},\n\t\t{\n\t\t\targ: argument{\n\t\t\t\ts: \"{{]]])\",\n\t\t\t},\n\t\t\tans: false,\n\t\t},\n\t}\n\n\tast := assert.New(t)\n\tfor _, exam := range examples {\n\t\tans, arg := exam.ans, exam.arg\n\t\tast.Equal(ans, isValid(arg.s),\n\t\t\t\"%v %v\", arg.s, ans)\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/021/ac021.go",
    "content": "package problem021\n\ntype ListNode struct {\n\tVal  int\n\tNext *ListNode\n}\n\nfunc mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {\n\tif nil == l1 {\n\t\treturn l2\n\t}\n\tif nil == l2 {\n\t\treturn l1\n\t}\n\n\tif l1.Val < l2.Val {\n\t\tl1.Next = mergeTwoLists(l1.Next, l2)\n\t\treturn l1\n\t} else {\n\t\tl2.Next = mergeTwoLists(l1, l2.Next)\n\t\treturn l2\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/026/ac026.go",
    "content": "package problem026\n\nfunc removeDuplicates(nums []int) int {\n\tif nil == nums || len(nums) < 1 {\n\t\treturn 0\n\t}\n\n\tnewLength := 1\n\tfor i := 1; i < len(nums); i++ {\n\t\tif nums[i] != nums[newLength-1] {\n\t\t\tnums[newLength] = nums[i]\n\t\t\tnewLength++\n\t\t}\n\t}\n\treturn newLength\n}\n"
  },
  {
    "path": "algorithm/leetcode/027/ac027.go",
    "content": "package problem027\n\nfunc removeElement(nums []int, val int) int {\n\tif nil == nums || len(nums) < 1 {\n\t\treturn 0\n\t}\n\n\tvar idx int\n\tfor i := 0; i < len(nums); i++ {\n\t\tif nums[i] != val {\n\t\t\tnums[idx] = nums[i]\n\t\t\tidx++\n\t\t}\n\t}\n\treturn idx\n}\n"
  },
  {
    "path": "algorithm/leetcode/028/ac028.go",
    "content": "package problem028\n\nfunc strStr(haystack string, needle string) int {\n\tif \"\" == needle {\n\t\treturn 0\n\t}\n\n\tfor i := 0; i <= len(haystack)-len(needle); i++ {\n\t\tfor j := 0; j < len(needle) && haystack[i+j] == needle[j]; j++ {\n\t\t\tif j == len(needle)-1 {\n\t\t\t\treturn i\n\t\t\t}\n\t\t}\n\t}\n\treturn -1\n}\n"
  },
  {
    "path": "algorithm/leetcode/035/ac035.go",
    "content": "package problem035\n\nfunc searchInsert(nums []int, target int) int {\n\tif nil == nums || len(nums) < 1 {\n\t\treturn 0\n\t}\n\n\tstart, end := 0, len(nums)-1\n\tfor start <= end {\n\t\tmiddle := (start + end) / 2\n\t\tif nums[middle] == target {\n\t\t\treturn middle\n\t\t} else if nums[middle] < target {\n\t\t\tstart = middle + 1\n\t\t} else {\n\t\t\tend = middle - 1\n\t\t}\n\t}\n\treturn start\n}\n"
  },
  {
    "path": "algorithm/leetcode/035/ac035_test.go",
    "content": "package problem035\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_searchInsert(t *testing.T) {\n\tdata := []int{1, 3, 5, 6}\n\ttarget := 2\n\tfmt.Println(searchInsert(data, target))\n}\n"
  },
  {
    "path": "algorithm/leetcode/038/ac038.go",
    "content": "package problem038\n\nimport \"strconv\"\n\nfunc countAndSay(n int) string {\n\tif 0 == n {\n\t\treturn \"\"\n\t}\n\n\tans := \"1\"\n\tfor n--; n > 0; n-- {\n\t\tcurrent := \"\"\n\t\tfor i := 0; i < len(ans); i++ {\n\t\t\tcount := 1\n\t\t\tfor i+1 < len(ans) && ans[i] == ans[i+1] {\n\t\t\t\tcount++\n\t\t\t\ti++\n\t\t\t}\n\t\t\tcurrent += strconv.Itoa(count) + string(ans[i])\n\t\t}\n\t\tans = current\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/053/ac053.go",
    "content": "package problem053\n\nfunc maxSubArray(nums []int) int {\n\tif nil == nums || len(nums) < 1 {\n\t\treturn 0\n\t}\n\n\tpreSum, maxSum := nums[0], nums[0]\n\tfor i := 1; i < len(nums); i++ {\n\t\tif preSum+nums[i] <= nums[i] {\n\t\t\tpreSum = nums[i]\n\t\t} else {\n\t\t\tpreSum += nums[i]\n\t\t}\n\t\tif preSum > maxSum {\n\t\t\tmaxSum = preSum\n\t\t}\n\t}\n\treturn maxSum\n}\n"
  },
  {
    "path": "algorithm/leetcode/058/ac058.go",
    "content": "package problem058\n\nimport (\n\t\"strings\"\n)\n\nfunc lengthOfLastWord(s string) int {\n\tsubArray := strings.Split(s, \" \")\n\tfor i := len(subArray) - 1; i >= 0; i-- {\n\t\tlength := len(subArray[i])\n\t\tif length > 0 {\n\t\t\treturn length\n\t\t}\n\t}\n\treturn 0\n}\n\nfunc lengthOfLastWord2(s string) int {\n\tlen, tail := 0, len(s)-1\n\tfor tail >= 0 && s[tail] == ' ' {\n\t\ttail--\n\t}\n\tfor tail >= 0 && s[tail] != ' ' {\n\t\tlen++\n\t\ttail--\n\t}\n\treturn len\n}\n"
  },
  {
    "path": "algorithm/leetcode/058/ac058_test.go",
    "content": "package problem058\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_lengthOfLastWord(t *testing.T) {\n\ttext1 := \"Hello World\"\n\ttext2 := \"a \"\n\tfmt.Println(lengthOfLastWord(text1))\n\tfmt.Println(lengthOfLastWord(text2))\n\n\tfmt.Println(lengthOfLastWord2(text1))\n\tfmt.Println(lengthOfLastWord2(text2))\n\n\ttext3 := \"你好golang\"\n\tfmt.Println(len(text3))\n\tfmt.Printf(\"%v %q %T\\n\", text3[0], text3[0], text3[0])\n\tfmt.Printf(\"%v %q %T\\n\", text3[6], text3[6], text3[6])\n\n\ttext4 := '中'\n\ttext5 := 'g'\n\tfmt.Printf(\"%v %T\\n\", text4, text4)\n\tfmt.Printf(\"%q %T\\n\", text5, text5)\n\n}\n"
  },
  {
    "path": "algorithm/leetcode/066/ac066.go",
    "content": "package problem066\n\nfunc plusOne(digits []int) []int {\n\tfor i := len(digits) - 1; i >= 0; i-- {\n\t\tif 9 != digits[i] {\n\t\t\tdigits[i]++\n\t\t\tbreak\n\t\t} else {\n\t\t\tdigits[i] = 0\n\t\t}\n\t}\n\tif 0 == digits[0] {\n\t\tnewAns := make([]int, len(digits)+1)\n\t\tnewAns[0] = 1\n\t\treturn newAns\n\t}\n\treturn digits\n}\n"
  },
  {
    "path": "algorithm/leetcode/067/ac067.go",
    "content": "package problem067\n\nfunc addBinary(a string, b string) string {\n\taChar := []rune(a)\n\tbChar := []rune(b)\n\tvar s []rune\n\tvar c rune\n\ti, j := len(a)-1, len(b)-1\n\tfor i >= 0 || j >= 0 || c == 1 {\n\t\tif i >= 0 {\n\t\t\tc += aChar[i] - '0'\n\t\t\ti--\n\t\t}\n\t\tif j >= 0 {\n\t\t\tc += bChar[j] - '0'\n\t\t\tj--\n\t\t}\n\t\ts = append(s, c%2+'0')\n\t\tc /= 2\n\t}\n\n\tfor i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {\n\t\ts[i], s[j] = s[j], s[i]\n\t}\n\n\treturn string(s)\n}\n\nfunc addBinary2(a string, b string) string {\n\ts := make([]byte, 0)\n\tvar c byte\n\ti, j := len(a)-1, len(b)-1\n\tfor i >= 0 || j >= 0 || 1 == c {\n\t\tif i >= 0 {\n\t\t\tc += a[i] - '0'\n\t\t\ti--\n\t\t}\n\t\tif j >= 0 {\n\t\t\tc += b[j] - '0'\n\t\t\tj--\n\t\t}\n\t\ts = append(s, c%2+'0')\n\t\tc /= 2\n\t}\n\tfor i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {\n\t\ts[i], s[j] = s[j], s[i]\n\t}\n\n\treturn string(s)\n}\n"
  },
  {
    "path": "algorithm/leetcode/067/ac067_test.go",
    "content": "package problem067\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_addBinary(t *testing.T) {\n\ta := \"11\"\n\tb := \"01\"\n\tfmt.Println(addBinary(a, b))\n\tfmt.Println(addBinary2(a, b))\n}\n"
  },
  {
    "path": "algorithm/leetcode/069/ac069.go",
    "content": "package problem069\n\nfunc mySqrt(x int) int {\n\tif 0 == x {\n\t\treturn 0\n\t}\n\n\tn := x\n\tfor n*n > x {\n\t\tn = (n + x/n) / 2\n\t}\n\treturn n\n}\n"
  },
  {
    "path": "algorithm/leetcode/069/ac069_test.go",
    "content": "package problem069\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_mySqrt(t *testing.T) {\n\tfmt.Println(mySqrt(9))\n}\n"
  },
  {
    "path": "algorithm/leetcode/070/ac070.go",
    "content": "package problem070\n\nfunc climbStairs(n int) int {\n\tif 1 == n {\n\t\treturn 1\n\t}\n\n\tf := make([]int, n+1)\n\tf[1], f[2] = 1, 2\n\n\tfor i := 3; i < len(f); i++ {\n\t\tf[i] = f[i-1] + f[i-2]\n\t}\n\treturn f[n]\n}\n\nfunc climbStairs2(n int) int {\n\ta, b := 1, 1\n\n\tfor ; n > 0; n-- {\n\t\ta, b = b, a+b\n\t}\n\treturn a\n}\n"
  },
  {
    "path": "algorithm/leetcode/083/ac083.go",
    "content": "package problem083\n\ntype ListNode struct {\n\tVal  int\n\tNext *ListNode\n}\n\nfunc deleteDuplicates(head *ListNode) *ListNode {\n\tif nil == head || nil == head.Next {\n\t\treturn head\n\t}\n\n\tprePtr := head\n\tcurrentPtr := head.Next\n\tlastValue := prePtr.Val\n\n\tfor nil != currentPtr {\n\t\tif currentPtr.Val != lastValue {\n\t\t\tlastValue = currentPtr.Val\n\t\t\tprePtr = currentPtr\n\t\t\tcurrentPtr = currentPtr.Next\n\t\t} else {\n\t\t\tprePtr.Next = currentPtr.Next\n\t\t\tcurrentPtr = currentPtr.Next\n\t\t}\n\t}\n\treturn head\n}\n"
  },
  {
    "path": "algorithm/leetcode/088/ac088.go",
    "content": "package problem088\n\nfunc merge(nums1 []int, m int, nums2 []int, n int) {\n\tidm, idn := m-1, n-1\n\tfor i := m + n - 1; i >= 0; i-- {\n\t\tif idm < 0 {\n\t\t\tnums1[i] = nums2[idn]\n\t\t\tidn--\n\t\t\tcontinue\n\t\t}\n\t\tif idn < 0 {\n\t\t\tnums1[i] = nums1[idm]\n\t\t\tidm--\n\t\t\tcontinue\n\t\t}\n\t\tif nums1[idm] >= nums2[idn] {\n\t\t\tnums1[i] = nums1[idm]\n\t\t\tidm--\n\t\t\tcontinue\n\t\t}\n\t\tif nums1[idm] < nums2[idn] {\n\t\t\tnums1[i] = nums2[idn]\n\t\t\tidn--\n\t\t\tcontinue\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/100/ac100.go",
    "content": "package problem100\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc isSameTree(p *TreeNode, q *TreeNode) bool {\n\tif nil == p && nil == q {\n\t\treturn true\n\t} else if nil == p || nil == q {\n\t\treturn false\n\t} else if p.Val == q.Val {\n\t\treturn isSameTree(p.Left, q.Left) && isSameTree(p.Right, q.Right)\n\t} else {\n\t\treturn false\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/101/ac101.go",
    "content": "package problem101\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc isSymmetric(root *TreeNode) bool {\n\treturn nil == root || isSame(root.Left, root.Right)\n}\n\nfunc isSame(left, right *TreeNode) bool {\n\tif nil == left || nil == right {\n\t\treturn left == right\n\t} else if left.Val != right.Val {\n\t\treturn false\n\t} else {\n\t\treturn isSame(left.Left, right.Right) && isSame(left.Right, right.Left)\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/104/ac104.go",
    "content": "package problem104\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc maxDepth(root *TreeNode) int {\n\tif nil == root {\n\t\treturn 0\n\t}\n\n\tleft := maxDepth(root.Left)\n\tright := maxDepth(root.Right)\n\n\tif left >= right {\n\t\treturn left + 1\n\t} else {\n\t\treturn right + 1\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/107/ac107.go",
    "content": "package problem107\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc levelOrderBottom(root *TreeNode) [][]int {\n\tres := make([][]int, 0)\n\tvar dfs func(*TreeNode, int)\n\tdfs = func(root *TreeNode, level int) {\n\t\tif root == nil {\n\t\t\treturn\n\t\t}\n\n\t\t// 出现了新的 level\n\t\tif level >= len(res) {\n\t\t\tres = append([][]int{{}}, res...)\n\t\t}\n\t\tn := len(res)\n\t\tres[n-level-1] = append(res[n-level-1], root.Val)\n\n\t\tdfs(root.Left, level+1)\n\t\tdfs(root.Right, level+1)\n\t}\n\n\tdfs(root, 0)\n\treturn res\n}\n"
  },
  {
    "path": "algorithm/leetcode/107/ac107_test.go",
    "content": "package problem107\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_levelOrderBottom(t *testing.T) {\n\tnode15 := TreeNode{Val: 15, Left: nil, Right: nil}\n\tnode7 := TreeNode{Val: 7, Left: nil, Right: nil}\n\tnode9 := TreeNode{Val: 9, Left: nil, Right: nil}\n\tnode20 := TreeNode{Val: 20, Left: &node15, Right: &node7}\n\tnode3 := TreeNode{Val: 3, Left: &node9, Right: &node20}\n\n\tresult := levelOrderBottom(&node3)\n\tfmt.Println(result)\n}\n"
  },
  {
    "path": "algorithm/leetcode/108/ac108.go",
    "content": "package problem108\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc sortedArrayToBST(nums []int) *TreeNode {\n\tif len(nums) < 1 {\n\t\treturn nil\n\t}\n\n\tmid := len(nums) / 2\n\treturn &TreeNode{\n\t\tVal:   nums[mid],\n\t\tLeft:  sortedArrayToBST(nums[:mid]),\n\t\tRight: sortedArrayToBST(nums[mid+1:]),\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/110/ac110.go",
    "content": "package problem110\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc isBalanced(root *TreeNode) bool {\n\tif nil == root {\n\t\treturn true\n\t}\n\tdiff := depth(root.Left) - depth(root.Right)\n\tif diff > 1 || diff < -1 {\n\t\treturn false\n\t}\n\treturn isBalanced(root.Left) && isBalanced(root.Right)\n}\n\nfunc depth(root *TreeNode) int {\n\tif nil == root {\n\t\treturn 0\n\t}\n\n\tleft := depth(root.Left)\n\tright := depth(root.Right)\n\n\tif left > right {\n\t\treturn left + 1\n\t} else {\n\t\treturn right + 1\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/111/ac111.go",
    "content": "package problem111\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc minDepth(root *TreeNode) int {\n\tif nil == root {\n\t\treturn 0\n\t}\n\n\tleftDepth := minDepth(root.Left)\n\trightDepth := minDepth(root.Right)\n\n\tif 0 == leftDepth || 0 == rightDepth {\n\t\treturn leftDepth + rightDepth + 1\n\t} else {\n\t\tif leftDepth < rightDepth {\n\t\t\treturn leftDepth + 1\n\t\t} else {\n\t\t\treturn rightDepth + 1\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/112/ac112.go",
    "content": "package problem112\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc hasPathSum(root *TreeNode, sum int) bool {\n\tif nil == root {\n\t\treturn false\n\t}\n\n\t// 判断叶子节点的值是否与指定值相等\n\tif nil == root.Left && nil == root.Right {\n\t\treturn root.Val == sum\n\t} else {\n\t\treturn hasPathSum(root.Left, sum-root.Val) || hasPathSum(root.Right, sum-root.Val)\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/118/ac118.go",
    "content": "package problem118\n\nfunc generate(numRows int) [][]int {\n\tif numRows < 1 {\n\t\treturn nil\n\t}\n\n\tans := make([][]int, 0)\n\n\tfor i := 0; i < numRows; i++ {\n\t\toneLine := make([]int, i+1)\n\t\toneLine[0] = 1\n\t\toneLine[i] = 1\n\n\t\tfor j := 1; j < i; j++ {\n\t\t\toneLine[j] = ans[i-1][j-1] + ans[i-1][j]\n\t\t}\n\n\t\tans = append(ans, oneLine)\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/119/ac119.go",
    "content": "package problem119\n\nfunc getRow(rowIndex int) []int {\n\tif rowIndex < 0 {\n\t\treturn nil\n\t}\n\n\tvi := make([]int, rowIndex+1)\n\tvi[0] = 1\n\tfor i := 0; i <= rowIndex; i++ {\n\t\tfor j := i; j > 0; j-- {\n\t\t\tvi[j] = vi[j] + vi[j-1]\n\t\t}\n\t}\n\treturn vi\n}\n"
  },
  {
    "path": "algorithm/leetcode/120/ac120.go",
    "content": "package problem120\n\n// 自下向上推导\n// ans数组保存的是：到达下一行某位置的最小路径和\nfunc minimumTotal(triangle [][]int) int {\n\tans := make([]int, len(triangle)+1)\n\n\tfor i := len(triangle) - 1; i >= 0; i-- {\n\t\tfor j := 0; j < len(triangle[i]); j++ {\n\t\t\tans[j] = myMin(ans[j], ans[j+1]) + triangle[i][j]\n\t\t}\n\t}\n\n\treturn ans[0]\n}\n\nfunc myMin(a, b int) int {\n\tif a < b {\n\t\treturn a\n\t}\n\treturn b\n}\n"
  },
  {
    "path": "algorithm/leetcode/120/ac120_test.go",
    "content": "package problem120\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_minimumTotal(t *testing.T) {\n\tdata := [][]int{\n\t\t{2},\n\t\t{3, 4},\n\t\t{6, 5, 7},\n\t\t{4, 1, 8, 3}}\n\n\tfmt.Println(minimumTotal(data))\n}\n"
  },
  {
    "path": "algorithm/leetcode/121/ac121.go",
    "content": "package problem121\n\nfunc maxProfit(prices []int) int {\n\tif len(prices) < 1 {\n\t\treturn 0\n\t}\n\n\tmaxProfit := 0\n\tminPrice := prices[0]\n\tfor i := 1; i < len(prices); i++ {\n\t\tif prices[i] < minPrice {\n\t\t\tminPrice = prices[i]\n\t\t\tcontinue\n\t\t}\n\n\t\tcurrent := prices[i] - minPrice\n\n\t\tif current > maxProfit {\n\t\t\tmaxProfit = current\n\t\t}\n\t}\n\treturn maxProfit\n}\n"
  },
  {
    "path": "algorithm/leetcode/121/ac121_test.go",
    "content": "package problem121\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_maxProfit(t *testing.T) {\n\tdata := []int{7, 1, 5, 3, 6, 4}\n\n\tfmt.Println(maxProfit(data))\n}\n"
  },
  {
    "path": "algorithm/leetcode/122/ac122.go",
    "content": "package problem122\n\nfunc maxProfit(prices []int) int {\n\tif len(prices) < 1 {\n\t\treturn 0\n\t}\n\n\tans := 0\n\tfor i := 1; i < len(prices); i++ {\n\t\tif prices[i] > prices[i-1] {\n\t\t\tans += prices[i] - prices[i-1]\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/125/ac125.go",
    "content": "package problem125\n\nfunc isPalindrome(s string) bool {\n\tif len(s) <= 1 {\n\t\treturn true\n\t}\n\n\tleft, right := 0, len(s)-1\n\tfor left < right {\n\t\tfor left < right && !isCharacter(s[left]) {\n\t\t\tleft++\n\t\t}\n\t\tfor left < right && !isCharacter(s[right]) {\n\t\t\tright--\n\t\t}\n\n\t\tif lowerCharacter(s[left]) != lowerCharacter(s[right]) {\n\t\t\treturn false\n\t\t}\n\t\tleft++\n\t\tright--\n\t}\n\treturn true\n}\n\nfunc isCharacter(c byte) bool {\n\tif (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') {\n\t\treturn true\n\t} else {\n\t\treturn false\n\t}\n}\n\nfunc lowerCharacter(c byte) byte {\n\tif c >= 'A' && c <= 'Z' {\n\t\treturn c + 'a' - 'A'\n\t}\n\treturn c\n}\n"
  },
  {
    "path": "algorithm/leetcode/125/ac125_test.go",
    "content": "package problem125\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_isCharacter(t *testing.T) {\n\tstr := \"A man, a plan, a canal: Panama\"\n\tfmt.Println(isPalindrome(str))\n\n\tstr2 := \"0P\"\n\tfmt.Println(isPalindrome(str2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/136/ac136.go",
    "content": "package problem136\n\nfunc singleNumber(nums []int) int {\n\tans := 0\n\tfor _, value := range nums{\n\t\tans ^= value\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/137/ac137.go",
    "content": "package problem137\n\nfunc singleNumber(nums []int) int {\n\tdict := make(map[int]int, 0)\n\n\tfor _, v := range nums {\n\t\ttemp, ok := dict[v]\n\t\tif !ok {\n\t\t\tdict[v] = 1\n\t\t} else if 2 == temp {\n\t\t\tdelete(dict, v)\n\t\t} else {\n\t\t\tdict[v]++\n\t\t}\n\t}\n\tfor k := range dict {\n\t\treturn k\n\t}\n\n\treturn -1\n}\n\nfunc singleNumber2(nums []int) int {\n\tones, twos := 0, 0\n\tfor i := 0; i < len(nums); i++ {\n\t\tones = (ones ^ nums[i]) & ^twos\n\t\ttwos = (twos ^ nums[i]) & ^ones\n\t}\n\treturn ones\n}\n\nfunc singleNumber3(nums []int) int {\n\tone, two, three := 0, 0, 0\n\tfor _, v := range nums {\n\t\t//当新来的为0时，two = two | 0，two不变，当新来的为1时，（当one此时为0，则two = two | 0，two不变；当one此时为1时，则two = two | 1，two变为1\n\t\ttwo |= one & v\n\t\t//新来的为0，one不变，新来为1时，one是0、1 交替改变\n\t\tone ^= v\n\t\t//当one和two为1是，three为1（此时代表要把one和two清零了）\n\t\tthree = one & two\n\t\t//把one清0\n\t\tone &= ^three\n\t\t//把two清0\n\t\ttwo &= ^three\n\t}\n\treturn one\n}\n\n// 遍历32次每次记录某位的出现的次数，如果不能被三整除，说明那个出现一次的就在该位有值，那么ans 或该位一下就可以了\nfunc singleNumber4(nums []int) int {\n\tvar ans = 0\n\tvar i uint8\n\tfor i = 0; i < 32; i++ {\n\t\tcnt := 0\n\t\tfor _, v := range nums {\n\t\t\tif ((v >> i) & 1) == 1 {\n\t\t\t\tcnt++\n\t\t\t}\n\t\t}\n\t\tans |= (cnt % 3) << i\n\t}\n\treturn int(int32(ans))\n}\n"
  },
  {
    "path": "algorithm/leetcode/137/ac137_test.go",
    "content": "package problem137\n\nimport (\n\t\"fmt\"\n\t\"testing\"\n)\n\nfunc Test_singleNumber(t *testing.T) {\n\tnums1 := []int{2, 2, 3, 2}\n\n\tfmt.Println(singleNumber(nums1))\n\tfmt.Println(singleNumber4(nums1))\n}\n"
  },
  {
    "path": "algorithm/leetcode/160/ac160.go",
    "content": "package problem160\n\ntype ListNode struct {\n\tVal  int\n\tNext *ListNode\n}\n\nfunc getIntersectionNode(headA, headB *ListNode) *ListNode {\n\tif nil == headA || nil == headB {\n\t\treturn nil\n\t}\n\n\tptrA, ptrB := headA, headB;\n\tfor ptrA != ptrB {\n\t\tif nil == ptrA {\n\t\t\tptrA = headB\n\t\t} else {\n\t\t\tptrA = ptrA.Next\n\t\t}\n\n\t\tif nil == ptrB {\n\t\t\tptrB = headA\n\t\t} else {\n\t\t\tptrB = ptrB.Next\n\t\t}\n\t}\n\n\treturn ptrA\n}\n"
  },
  {
    "path": "algorithm/leetcode/160/ac160_test.go",
    "content": "package problem160\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\n// 两个单链表的相交节点为 node4 该节点值为 4\n// node11 -> node22\n//                         -> node4 -> node5 -> node6\n// node1 -> node2 -> node3\nfunc Test_getIntersectionNode(t *testing.T) {\n\tnode6 := ListNode{Val: 6, Next: nil}\n\tnode5 := ListNode{Val: 5, Next: &node6}\n\tnode4 := ListNode{Val: 4, Next: &node5}\n\tnode3 := ListNode{Val: 3, Next: &node4}\n\tnode2 := ListNode{Val: 2, Next: &node3}\n\tnode1 := ListNode{Val: 1, Next: &node2}\n\tnode22 := ListNode{Val: 22, Next: &node4}\n\tnode11 := ListNode{Val: 11, Next: &node22}\n\n\tfmt.Println(getIntersectionNode(&node11, &node1).Val)\n}\n"
  },
  {
    "path": "algorithm/leetcode/167/ac167.go",
    "content": "package problem167\n\nfunc twoSum(numbers []int, target int) []int {\n\tleft, right := 0, len(numbers)-1\n\tfor left < right {\n\t\tsum := numbers[left] + numbers[right]\n\t\tif sum < target {\n\t\t\tleft++\n\t\t} else if sum > target {\n\t\t\tright--\n\t\t} else {\n\t\t\treturn []int{left + 1, right + 1}\n\t\t}\n\t}\n\treturn nil\n}\n"
  },
  {
    "path": "algorithm/leetcode/168/ac141.go",
    "content": "package problem168\n\nfunc convertToTitle(n int) string {\n\tans := make([]byte, 0)\n\n\tfor n > 0 {\n\t\tn--\n\t\tans = append(ans, byte(n%26)+'A')\n\t\tn /= 26\n\t}\n\n\tfor i, j := 0, len(ans)-1; i < j; i, j = i+1, j-1 {\n\t\tans[i], ans[j] = ans[j], ans[i]\n\t}\n\treturn string(ans)\n}\n"
  },
  {
    "path": "algorithm/leetcode/168/ac141_test.go",
    "content": "package problem168\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_convertToTitle(t *testing.T) {\n\tfmt.Println(convertToTitle(27))\n}\n"
  },
  {
    "path": "algorithm/leetcode/169/ac169.go",
    "content": "package problem169\n\nfunc majorityElement(nums []int) int {\n\tif len(nums) < 1 {\n\t\treturn 0\n\t}\n\n\tcount, flag := 1, nums[0]\n\tfor i := 1; i < len(nums); i++ {\n\t\tif count < 1 {\n\t\t\tflag = nums[i]\n\t\t\tcount = 1\n\t\t\tcontinue\n\t\t}\n\t\tif nums[i] == flag {\n\t\t\tcount++\n\t\t} else {\n\t\t\tcount--\n\t\t}\n\t}\n\treturn flag\n}\n"
  },
  {
    "path": "algorithm/leetcode/171/ac171.go",
    "content": "package problem171\n\nfunc titleToNumber(s string) int {\n\tans := 0\n\tfor _, value := range s {\n\t\tans = int(value) - int('A') + 1 + ans*26\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/172/ac172.go",
    "content": "package problem172\n\nfunc trailingZeroes(n int) int {\n\tif 0 == n {\n\t\treturn 0\n\t} else {\n\t\treturn n/5 + trailingZeroes(n/5)\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/189/ac189.go",
    "content": "package problem189\n\nfunc rotate(nums []int, k int) {\n\tif nil == nums {\n\t\treturn\n\t}\n\n\tlength := len(nums)\n\tif k > length {\n\t\tk %= length\n\t}\n\tif 0 == k || k == length {\n\t\treturn\n\t}\n\n\treverse(nums)\n\treverse(nums[:k])\n\treverse(nums[k:])\n}\n\nfunc reverse(nums []int) {\n\tfor i, j := 0, len(nums)-1; i < j; i, j = i+1, j-1 {\n\t\tnums[i], nums[j] = nums[j], nums[i]\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/189/ac189_test.go",
    "content": "package problem189\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_rotate(t *testing.T) {\n\tnumbers := []int{1, 2, 3, 4, 5, 6, 7}\n\n\trotate(numbers, 3)\n\n\tfmt.Println(numbers)\n\n\tnumbers2 := []int{-1}\n\trotate(numbers2, 2)\n\tfmt.Println(numbers2)\n\n}\n"
  },
  {
    "path": "algorithm/leetcode/191/ac191.go",
    "content": "package problem191\n\nfunc hammingWeight(n uint32) int {\n\tans := 0\n\tfor 0 != n {\n\t\tn &= n - 1\n\t\tans++\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/191/ac191_test.go",
    "content": "package problem191\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_hammingWeight(t *testing.T) {\n\tfmt.Println(hammingWeight(uint32(11)))\n}\n"
  },
  {
    "path": "algorithm/leetcode/198/ac198.go",
    "content": "package problem198\n\nfunc rob(nums []int) int {\n\tif nil == nums || len(nums) < 1 {\n\t\treturn 0\n\t}\n\n\tif 1 == len(nums) {\n\t\treturn nums[0]\n\t} else if 2 == len(nums) {\n\t\treturn maxInt(nums[0], nums[1])\n\t}\n\n\tf := make([]int, len(nums))\n\tf[0] = nums[0]\n\tf[1] = maxInt(nums[0], nums[1])\n\tfor i := 2; i < len(nums); i++ {\n\t\tf[i] = maxInt(nums[i]+f[i-2], f[i-1])\n\t}\n\n\treturn f[len(nums)-1]\n}\n\nfunc maxInt(a, b int) int {\n\tif a > b {\n\t\treturn a\n\t}\n\treturn b\n}\n"
  },
  {
    "path": "algorithm/leetcode/202/ac202.go",
    "content": "package problem202\n\nfunc isHappy(n int) bool {\n\tslow, fast := n, n\n\tfor {\n\t\tslow = digitSquareSum(slow)\n\t\tfast = digitSquareSum(fast)\n\t\tfast = digitSquareSum(fast)\n\n\t\tif 1 == fast {\n\t\t\treturn true\n\t\t}\n\t\tif slow == fast {\n\t\t\tbreak\n\t\t}\n\t}\n\treturn false\n}\n\nfunc digitSquareSum(n int) int {\n\tsum, tmp := 0, 0\n\tfor ; 0 != n; n /= 10 {\n\t\ttmp = n % 10\n\t\tsum += tmp * tmp\n\t}\n\treturn sum\n}\n"
  },
  {
    "path": "algorithm/leetcode/203/ac203.go",
    "content": "package problem203\n\ntype ListNode struct {\n\tVal  int\n\tNext *ListNode\n}\n\n// 递归写法 效率低\nfunc removeElements(head *ListNode, val int) *ListNode {\n\tif nil == head {\n\t\treturn nil\n\t}\n\n\thead.Next = removeElements(head.Next, val)\n\n\tif head.Val == val {\n\t\treturn head.Next\n\t} else {\n\t\treturn head\n\t}\n}\n\n// 非递归 效率高\nfunc removeElements2(head *ListNode, val int) *ListNode {\n\tfor nil != head && val == head.Val {\n\t\thead = head.Next\n\t}\n\tcurrentPtr := head\n\n\tfor nil != currentPtr && nil != currentPtr.Next {\n\t\tif currentPtr.Next.Val == val {\n\t\t\tcurrentPtr.Next = currentPtr.Next.Next\n\t\t} else {\n\t\t\tcurrentPtr = currentPtr.Next\n\t\t}\n\t}\n\n\treturn head\n}\n"
  },
  {
    "path": "algorithm/leetcode/204/ac204.go",
    "content": "package problem204\n\nfunc countPrimes(n int) int {\n\tnotPrime := make([]bool, n)\n\tcount := 0\n\n\tfor i := 2; i < n; i++ {\n\t\tif !notPrime[i] {\n\t\t\tcount++\n\n\t\t\tif temp := i * i; temp < n {\n\t\t\t\tfor j := temp; j < n; j += i {\n\t\t\t\t\tnotPrime[j] = true\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn count\n}\n"
  },
  {
    "path": "algorithm/leetcode/205/ac205.go",
    "content": "package problem205\n\nfunc isIsomorphic(s string, t string) bool {\n\tlength := len(s)\n\tnum1 := make([]int, 256)\n\tnum2 := make([]int, 256)\n\n\tfor i := 0; i < length; i++ {\n\t\tif num1[s[i]] != num2[t[i]] {\n\t\t\treturn false\n\t\t}\n\t\tnum1[s[i]] = i + 1\n\t\tnum2[t[i]] = i + 1\n\t}\n\treturn true\n}\n"
  },
  {
    "path": "algorithm/leetcode/205/ac205_test.go",
    "content": "package problem205\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_isIsomorphic(t *testing.T) {\n\tstr1 := \"egg\"\n\tstr2 := \"add\"\n\tfmt.Println(isIsomorphic(str1, str2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/206/ac206.go",
    "content": "package problem206\n\ntype ListNode struct {\n\tVal  int\n\tNext *ListNode\n}\n\nfunc reverseList(head *ListNode) *ListNode {\n\tvar newHead *ListNode\n\tfor nil != head {\n\t\tnextNode := head.Next\n\t\thead.Next = newHead\n\t\tnewHead = head\n\t\thead = nextNode\n\t}\n\treturn newHead\n}\n\nfunc reverseList1(head *ListNode) *ListNode {\n\treturn reverseCore(head, nil)\n}\n\nfunc reverseCore(head, newHead *ListNode) *ListNode {\n\tif nil == head {\n\t\treturn newHead\n\t}\n\n\tnextNode := head.Next\n\thead.Next = newHead\n\treturn reverseCore(nextNode, head)\n}\n"
  },
  {
    "path": "algorithm/leetcode/217/ac217.go",
    "content": "package problem217\n\nimport \"sort\"\n\nfunc containsDuplicate(nums []int) bool {\n\tdict := make(map[int]int, len(nums))\n\n\tfor _, value := range nums {\n\t\tdict[value]++\n\t}\n\n\tfor _, v := range dict {\n\t\tif v > 1 {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc containsDuplicate2(nums []int) bool {\n\tsort.Ints(nums)\n\n\tfor i := 1; i < len(nums); i++ {\n\t\tif nums[i-1] == nums[i] {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n"
  },
  {
    "path": "algorithm/leetcode/219/ac219.go",
    "content": "package problem219\n\nfunc containsNearbyDuplicate(nums []int, k int) bool {\n\tdict := make(map[int]int, len(nums))\n\n\tfor i := 0; i < len(nums); i++ {\n\t\tif value, ok := dict[nums[i]]; ok {\n\t\t\tif -k <= value-i || value-i <= k {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\tdict[nums[i]] = i\n\t}\n\n\treturn false\n}\n"
  },
  {
    "path": "algorithm/leetcode/226/ac226.go",
    "content": "package problem226\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc invertTree(root *TreeNode) *TreeNode {\n\tif nil == root {\n\t\treturn nil\n\t}\n\n\treturn &TreeNode{Val: root.Val, Left: invertTree(root.Right), Right: invertTree(root.Left)}\n}\n"
  },
  {
    "path": "algorithm/leetcode/231/ac231.go",
    "content": "package problem231\n\nfunc isPowerOfTwo(n int) bool {\n\tif n <= 0 {\n\t\treturn false\n\t}\n\n\treturn 0 == (n & (n - 1))\n}\n"
  },
  {
    "path": "algorithm/leetcode/234/ac234.go",
    "content": "package problem234\n\ntype ListNode struct {\n\tVal  int\n\tNext *ListNode\n}\n\nvar h *ListNode\n\nfunc isPalindrome(head *ListNode) bool {\n\tif nil == head {\n\t\treturn true\n\t}\n\n\tif nil == h {\n\t\th = head\n\t}\n\tflag := true\n\tif nil != head.Next {\n\t\tflag = flag && isPalindrome(head.Next)\n\t}\n\n\tflag = flag && (h.Val == head.Val)\n\th = h.Next\n\treturn flag\n}\n\nfunc isPalindrome2(head *ListNode) bool {\n\tnums := make([]int, 0, 128)\n\tfor nil != head {\n\t\tnums = append(nums, head.Val)\n\t\thead = head.Next\n\t}\n\n\tfor i, j := 0, len(nums)-1; i < j; {\n\t\tif nums[i] != nums[j] {\n\t\t\treturn false\n\t\t}\n\t\ti++\n\t\tj--\n\t}\n\treturn true\n}\n"
  },
  {
    "path": "algorithm/leetcode/258/ac258.go",
    "content": "package problem258\n\nfunc addDigits(num int) int {\n\treturn 1 + (num-1)%9\n}\n"
  },
  {
    "path": "algorithm/leetcode/263/ac263.go",
    "content": "package problem263\n\nfunc isUgly(num int) bool {\n\tfor i := 5; i >= 2 && num > 0; i-- {\n\t\tfor 0 == num%i {\n\t\t\tnum /= i\n\t\t}\n\t}\n\treturn 1 == num\n}\n"
  },
  {
    "path": "algorithm/leetcode/268/ac268.go",
    "content": "package problem268\n\nimport \"sort\"\n\nfunc missingNumber(nums []int) int {\n\tif nil == nums {\n\t\treturn -1\n\t}\n\n\tsort.Ints(nums)\n\tleft, right := 0, len(nums)-1\n\tfor left <= right {\n\t\tmiddle := (left + right) / 2\n\t\tif nums[middle] == middle {\n\t\t\tleft = middle + 1\n\t\t} else if nums[middle] > middle {\n\t\t\tright = middle - 1\n\t\t}\n\t}\n\treturn left\n}\n\nfunc missingNumber2(nums []int) int {\n\tsum := len(nums)\n\tfor i := 0; i < len(nums); i++ {\n\t\tsum -= i - nums[i]\n\t}\n\treturn sum\n}\n\nfunc missingNumber3(nums []int) int {\n\txor, i := 0, 0\n\tfor ; i < len(nums); i++ {\n\t\txor ^= i ^ nums[i]\n\t}\n\treturn xor ^ i\n}\n"
  },
  {
    "path": "algorithm/leetcode/268/ac268_test.go",
    "content": "package problem268\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_missingNumber(t *testing.T) {\n\tnums := []int{3, 0, 1}\n\tnums2 := []int{9, 6, 4, 2, 3, 5, 7, 0, 1}\n\tfmt.Println(missingNumber(nums))\n\tfmt.Println(missingNumber(nums2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/283/ac283.go",
    "content": "package problem283\n\nfunc moveZeroes(nums []int) {\n\tif nil == nums || len(nums) == 0 {\n\t\treturn\n\t}\n\n\tinsertPos := 0\n\tfor _, values := range nums {\n\t\tif 0 != values {\n\t\t\tnums[insertPos] = values\n\t\t\tinsertPos++\n\t\t}\n\t}\n\n\tfor insertPos < len(nums) {\n\t\tnums[insertPos] = 0\n\t\tinsertPos++\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/290/ac290.go",
    "content": "package problem290\n\nimport \"strings\"\n\nfunc wordPattern(pattern string, str string) bool {\n\twords := strings.Split(str, \" \")\n\tif len(pattern) != len(words) {\n\t\treturn false\n\t}\n\n\tdictPattern := make(map[byte]int)\n\tdictString := make(map[string]int)\n\tfor i := 0; i < len(pattern); i++ {\n\t\tpatternValue := dictPattern[pattern[i]]\n\t\tdictPattern[pattern[i]] = i+1\n\n\t\tstringValue := dictString[words[i]]\n\t\tdictString[words[i]] = i+1\n\n\t\tif patternValue != stringValue {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n"
  },
  {
    "path": "algorithm/leetcode/290/ac290_test.go",
    "content": "package problem290\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_wordPattern(t *testing.T) {\n\tpattern := \"abba\"\n\tstr := \"dog cat cat fish\"\n\n\tfmt.Println(wordPattern(pattern, str))\n}\n"
  },
  {
    "path": "algorithm/leetcode/292/ac292.go",
    "content": "package problem292\n\n// Nim游戏: 每次最多取 1~n 个石头\n// 精髓在于: 先手获胜的条件是 总石头数不能为 n+1 的倍数\nfunc canWinNim(n int) bool {\n\tif n < 1 {\n\t\treturn false\n\t}\n\n\treturn 0 != n % 4\n}\n"
  },
  {
    "path": "algorithm/leetcode/303/ac303.go",
    "content": "package problem303\n\ntype NumArray struct {\n\tdata []int\n}\n\nfunc Constructor(nums []int) NumArray {\n\tfor i := 1; i < len(nums); i++ {\n\t\tnums[i] += nums[i-1]\n\t}\n\n\treturn NumArray{data: nums}\n}\n\nfunc (this *NumArray) SumRange(i int, j int) int {\n\tif 0 == i {\n\t\treturn this.data[j]\n\t}\n\treturn this.data[j] - this.data[i-1]\n}\n"
  },
  {
    "path": "algorithm/leetcode/303/ac303_test.go",
    "content": "package problem303\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc TestNumArray_SumRange(t *testing.T) {\n\tnums := []int{-2, 0, 3, -5, 2, -1}\n\n\tobj := Constructor(nums)\n\tfmt.Println(obj.data)\n\tfmt.Println(obj.SumRange(0, 2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/326/ac326.go",
    "content": "package problem326\n\n// 1162261467 is 3^19,  3^20 is bigger than int\nfunc isPowerOfThree(n int) bool {\n\treturn n > 0 && (0 == 1162261467%n)\n}\n"
  },
  {
    "path": "algorithm/leetcode/326/ac326_test.go",
    "content": "package problem326\n\nimport \"testing\"\n\nfunc Test_isPowerOfThree(t *testing.T) {\n\ttype args struct {\n\t\tn int\n\t}\n\ttests := []struct {\n\t\tname string\n\t\targs args\n\t\twant bool\n\t}{\n\t\t// TODO: Add test cases.\n\t}\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\tif got := isPowerOfThree(tt.args.n); got != tt.want {\n\t\t\t\tt.Errorf(\"isPowerOfThree() = %v, want %v\", got, tt.want)\n\t\t\t}\n\t\t})\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/342/ac342.go",
    "content": "package problem342\n\n// 4的幂应该满足的条件:\n// 1. 大于0\n// 2. 该数字的二进制表示中 仅有1个bit位数字为 1\n// 3. 数字为 1 的bit位，应该出现在二进制数位的奇数位置\nfunc isPowerOfFour(num int) bool {\n\treturn num > 0 && (0 == num&(num-1)) && (num&0x55555555 != 0)\n}\n"
  },
  {
    "path": "algorithm/leetcode/344/ac344.go",
    "content": "package problem344\n\nfunc reverseString(s string) string {\n\tchar := []rune(s)\n\tfor i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {\n\t\tchar[i], char[j] = char[j], char[i]\n\t}\n\treturn string(char)\n}\n"
  },
  {
    "path": "algorithm/leetcode/344/ac344_test.go",
    "content": "package problem344\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_reverseString(t *testing.T) {\n\ts := \"abcdefg\"\n\n\tfmt.Println(reverseString(s))\n}\n"
  },
  {
    "path": "algorithm/leetcode/345/ac345.go",
    "content": "package problem345\n\nimport \"strings\"\n\nfunc reverseVowels(s string) string {\n\tif len(s) == 0 {\n\t\treturn s\n\t}\n\n\tvowels := \"aeiouAEIOU\"\n\tchars := []rune(s)\n\n\tfor start, end := 0, len(chars)-1; start < end; {\n\t\tfor start < end && !strings.ContainsRune(vowels, chars[start]) {\n\t\t\tstart++\n\t\t}\n\n\t\tfor start < end && !strings.ContainsRune(vowels, chars[end]) {\n\t\t\tend--\n\t\t}\n\n\t\tchars[start], chars[end] = chars[end], chars[start]\n\t\tstart++\n\t\tend--\n\t}\n\treturn string(chars)\n}\n"
  },
  {
    "path": "algorithm/leetcode/345/ac345_test.go",
    "content": "package problem345\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_reverseVowels(t *testing.T) {\n\tstr := \"hello\"\n\tstr2 := \"leetcode\"\n\tfmt.Println(reverseVowels(str))\n\tfmt.Println(reverseVowels(str2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/349/ac349.go",
    "content": "package problem349\n\nfunc intersection(nums1 []int, nums2 []int) []int {\n\tif nil == nums1 || len(nums1) == 0 {\n\t\treturn nums1\n\t}\n\tif nil == nums2 || len(nums2) == 0 {\n\t\treturn nums2\n\t}\n\n\tdict1 := make(map[int]int, 1)\n\tdict2 := make(map[int]int, 1)\n\tfor _, v := range nums1 {\n\t\tdict1[v]++\n\t}\n\tfor _, v := range nums2 {\n\t\tdict2[v]++\n\t}\n\n\tans := make([]int, 0)\n\tfor k := range dict1 {\n\t\tif _, ok := dict2[k]; ok {\n\t\t\tans = append(ans, k)\n\t\t}\n\t}\n\treturn ans\n}\n\nfunc intersection2(nums1 []int, nums2 []int) []int {\n\tdict := make(map[int]int)\n\tfor _, v := range nums1 {\n\t\tdict[v] = 1\n\t}\n\n\tfor _, v := range nums2 {\n\t\tif 1 == dict[v] {\n\t\t\tdict[v] = 2\n\t\t}\n\t}\n\n\tans := make([]int, 0)\n\tfor k, v := range dict {\n\t\tif 2 == v {\n\t\t\tans = append(ans, k)\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/349/ac349_test.go",
    "content": "package problem349\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_intersection(t *testing.T) {\n\tnum1 := []int{1, 2, 2, 1}\n\tnum2 := []int{2, 2}\n\n\tfmt.Println(intersection(num1, num2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/350/ac350.go",
    "content": "package problem350\n\nfunc intersect(nums1 []int, nums2 []int) []int {\n\tif nil == nums1 || len(nums1) == 0 {\n\t\treturn nums1\n\t}\n\tif nil == nums2 || len(nums2) == 0 {\n\t\treturn nums2\n\t}\n\n\tdict1 := make(map[int]int, 0)\n\tfor _, v := range nums1 {\n\t\tdict1[v]++\n\t}\n\n\tdict2 := make(map[int]int, 0)\n\tfor _, v := range nums2 {\n\t\tdict2[v]++\n\t}\n\n\tans := make([]int, 0)\n\tfor k1, v1 := range dict1 {\n\t\tif v2, ok := dict2[k1]; ok {\n\t\t\tfor repeat := minInt(v1, v2); repeat > 0; repeat-- {\n\t\t\t\tans = append(ans, k1)\n\t\t\t}\n\t\t}\n\t}\n\treturn ans\n}\n\nfunc minInt(a, b int) int {\n\tif a <= b {\n\t\treturn a\n\t}\n\treturn b\n}\n"
  },
  {
    "path": "algorithm/leetcode/350/ac350_test.go",
    "content": "package problem350\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_intersect(t *testing.T) {\n\tnum1 := []int{1, 2, 2, 1}\n\tnum2 := []int{2, 2}\n\n\tfmt.Println(intersect(num1, num2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/367/ac367.go",
    "content": "package problem367\n\nfunc isPerfectSquare(num int) bool {\n\tif 1 == num {\n\t\treturn true\n\t}\n\n\tfor middle := num / 2; middle >= 2; middle-- {\n\t\tresult := middle * middle\n\n\t\tif result == num {\n\t\t\treturn true\n\t\t} else if result < num {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn false\n}\n\nfunc isPerfectSquare2(num int) bool {\n\tlow, high := 1, num\n\n\tfor low <= high {\n\t\tmiddle := (low + high) >> 1\n\t\tresult := middle * middle\n\n\t\tif result == num {\n\t\t\treturn true\n\t\t} else if result < num {\n\t\t\tlow = middle + 1\n\t\t} else {\n\t\t\thigh = middle - 1\n\t\t}\n\t}\n\treturn false\n}\n"
  },
  {
    "path": "algorithm/leetcode/371/ac371.go",
    "content": "package problem371\n\nfunc getSum(a int, b int) int {\n\tif 0 == b {\n\t\treturn a\n\t}\n\tsum := a ^ b\n\tcarry := (a & b) << 1\n\treturn getSum(sum, carry)\n}\n"
  },
  {
    "path": "algorithm/leetcode/383/ac383.go",
    "content": "package problem383\n\nfunc canConstruct(ransomNote string, magazine string) bool {\n\tif len(ransomNote) == 0 && len(magazine) == 0 {\n\t\treturn true\n\t}\n\tif len(magazine) == 0 {\n\t\treturn false\n\t}\n\tif len(ransomNote) == 0 {\n\t\treturn true\n\t}\n\n\tdict1 := make(map[rune]int, 0)\n\tfor _, v := range ransomNote {\n\t\tdict1[v]++\n\t}\n\n\tdict2 := make(map[rune]int, 0)\n\tfor _, v := range magazine {\n\t\tdict2[v]++\n\t}\n\n\tfor k1, v1 := range dict1 {\n\t\tif v2, ok := dict2[k1]; !ok || v2 < v1 {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n"
  },
  {
    "path": "algorithm/leetcode/383/ac383_test.go",
    "content": "package problem383\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_canConstruct(t *testing.T) {\n\transom := \"aa\"\n\tmagazine := \"ab\"\n\n\tfmt.Println(canConstruct(ransom, magazine))\n}\n"
  },
  {
    "path": "algorithm/leetcode/387/ac387.go",
    "content": "package problem387\n\nfunc firstUniqChar(s string) int {\n\tif len(s) == 0 {\n\t\treturn -1\n\t}\n\n\tdict := make(map[rune]int, 0)\n\tfor _, v := range s {\n\t\tdict[v]++\n\t}\n\n\tans := -1\n\tfor id, v := range s {\n\t\tif 1 == dict[v] {\n\t\t\treturn id\n\t\t}\n\t}\n\treturn ans\n}\n\n// 效率更高\nfunc firstUniqChar2(s string) int {\n\tposition := [26]int{}\n\n\tfor _, v := range s {\n\t\tposition[v-'a']++\n\t}\n\tfor id, v := range s {\n\t\tif 1 == position[v-'a'] {\n\t\t\treturn id\n\t\t}\n\t}\n\treturn -1\n}\n"
  },
  {
    "path": "algorithm/leetcode/389/ac389.go",
    "content": "package problem389\n\nfunc findTheDifference(s string, t string) byte {\n\tdict1 := make(map[rune]int, 0)\n\tfor _, v := range s {\n\t\tdict1[v]++\n\t}\n\n\tdict2 := make(map[rune]int, 0)\n\tfor _, v := range t {\n\t\tdict2[v]++\n\t}\n\n\tfor k2, v2 := range dict2 {\n\t\tif v1 := dict1[k2]; v1 != v2 {\n\t\t\treturn byte(k2)\n\t\t}\n\t}\n\treturn byte(0)\n}\n\n// 更高效的做法\nfunc findTheDifference2(s string, t string) byte {\n\tans := byte(0)\n\n\tfor i := 0; i < len(s); i++ {\n\t\tans ^= s[i]\n\t}\n\tfor i := 0; i < len(t); i++ {\n\t\tans ^= t[i]\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/389/ac389_test.go",
    "content": "package problem389\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findTheDifference(t *testing.T) {\n\ts := \"a\"\n\ttt := \"aa\"\n\n\tfmt.Printf(\"%c\\n\", findTheDifference(s, tt))\n}\n"
  },
  {
    "path": "algorithm/leetcode/400/ac400.go",
    "content": "package problem400\n\nimport \"strconv\"\n\nfunc findNthDigit(n int) int {\n\t// 初始值定义 1 位数 共有 9 个, 起始数字为 1\n\tlen, count, start := 1, 9, 1\n\n\tfor n > len*count {\n\t\tn -= len * count\n\t\tlen++\n\t\tcount *= 10\n\t\tstart *= 10\n\t}\n\n\tstart += (n - 1) / len\n\ts := strconv.Itoa(start)\n\treturn int(s[(n-1)%len] - '0')\n}\n"
  },
  {
    "path": "algorithm/leetcode/400/ac400_test.go",
    "content": "package problem400\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findNthDigit(t *testing.T) {\n\tfmt.Println(findNthDigit(3))\n\tfmt.Println(findNthDigit(11))\n\tfmt.Println(findNthDigit(31))\n}\n"
  },
  {
    "path": "algorithm/leetcode/404/ac404.go",
    "content": "package problem404\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc sumOfLeftLeaves(root *TreeNode) int {\n\tif nil == root {\n\t\treturn 0\n\t}\n\n\tsum := 0\n\tif nil != root.Left && nil == root.Left.Left && nil == root.Left.Right {\n\t\tsum += root.Left.Val\n\t} else {\n\t\tsum += sumOfLeftLeaves(root.Left)\n\t}\n\n\tsum += sumOfLeftLeaves(root.Right)\n\treturn sum\n}\n"
  },
  {
    "path": "algorithm/leetcode/405/ac405.go",
    "content": "package problem405\n\nfunc toHex(num int) string {\n\tcharMap := []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}\n\n\tif 0 == num {\n\t\treturn \"0\"\n\t}\n\n\tnumUint32 := uint32(num)\n\tans := make([]byte, 0)\n\tfor 0 != numUint32 {\n\t\tans = append(ans, charMap[numUint32&15])\n\t\tnumUint32 >>= 4\n\t}\n\n\tfor i, j := 0, len(ans)-1; i < j; {\n\t\tans[i], ans[j] = ans[j], ans[i]\n\t\ti++\n\t\tj--\n\t}\n\treturn string(ans)\n}\n"
  },
  {
    "path": "algorithm/leetcode/405/ac405_test.go",
    "content": "package problem405\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_toHex(t *testing.T) {\n\tfmt.Println(toHex(14))\n\tfmt.Println(toHex(-1))\n}\n"
  },
  {
    "path": "algorithm/leetcode/409/ac409.go",
    "content": "package problem409\n\n//1、统计所有字母的出现频率（分大小写）\n//2、统计只出现奇数次数字母的个数\n//3、如果2中结果不为0，字符串的长度减去2中的字母个数+1\n//\n//其中3的意思是，保留出现次数最多的那个奇数字母，剩下的需要全部减1变成偶数去构造\nfunc longestPalindrome(s string) int {\n\tdict := make(map[byte]int, 0)\n\tfor i := 0; i < len(s); i++ {\n\t\tdict[s[i]]++\n\t}\n\n\todd := 0\n\tfor _, v := range dict {\n\t\tif v&1 != 0 {\n\t\t\todd++\n\t\t}\n\t}\n\n\tans := len(s)\n\tif 0 != odd {\n\t\tans -= odd - 1\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/409/ac409_test.go",
    "content": "package problem409\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_longestPalindrome(t *testing.T) {\n\tstr := \"abccccdd\"\n\n\tfmt.Println(longestPalindrome(str))\n\n}\n"
  },
  {
    "path": "algorithm/leetcode/412/ac412.go",
    "content": "package problem412\n\nimport (\n\t\"strconv\"\n\t\"fmt\"\n)\n\nfunc fizzBuzz(n int) []string {\n\tans := make([]string, 0)\n\n\tfor i := 1; i <= n; i++ {\n\t\tans = append(ans, number(i))\n\t}\n\treturn ans\n}\n\nfunc number(n int) string {\n\tif 0 == n%3 && 0 == n%5 {\n\t\treturn \"FizzBuzz\"\n\t} else if 0 == n%5 {\n\t\treturn \"Buzz\"\n\t} else if 0 == n%3 {\n\t\treturn \"Fizz\"\n\t} else {\n\t\treturn strconv.Itoa(n)\n\t}\n}\n\nfunc fizzBuzz2(n int) []string {\n\tans := make([]string, 0)\n\n\tfor i, fizz, buzz := 1, 0, 0; i <= n; i++ {\n\t\tfizz++\n\t\tbuzz++\n\t\tif 3 == fizz && 5 == buzz {\n\t\t\tans = append(ans, \"FizzBuzz\")\n\t\t\tfizz = 0\n\t\t\tbuzz = 0\n\t\t} else if 3 == fizz {\n\t\t\tans = append(ans, \"Fizz\")\n\t\t\tfizz = 0\n\t\t} else if 5 == buzz {\n\t\t\tans = append(ans, \"Buzz\")\n\t\t\tbuzz = 0\n\t\t} else {\n\t\t\tans = append(ans, fmt.Sprintf(\"%d\", i))\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/412/ac412_test.go",
    "content": "package problem412\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_fizzBuzz(t *testing.T) {\n\tfor _, v := range fizzBuzz2(15) {\n\t\tfmt.Println(v)\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/414/ac414.go",
    "content": "package problem414\n\nimport (\n\t\"sort\"\n)\n\nfunc thirdMax(nums []int) int {\n\tlength := len(nums)\n\tif length < 1 {\n\t\treturn -1\n\t}\n\n\tsort.Ints(nums)\n\n\tans := nums[length-1]\n\tj := 2\n\tfor i := length - 2; i >= 0 && j > 0; i-- {\n\t\tif nums[i] != ans {\n\t\t\tans = nums[i]\n\t\t\tj--\n\t\t}\n\t}\n\n\tif 0 != j {\n\t\tans = nums[length-1]\n\t}\n\treturn ans\n}\n\nfunc thirdMax2(nums []int) int {\n\tempty := [4]bool{true, true, true, true}\n\tmax := [4]int{}\n\tfor _, v := range nums {\n\t\tif (!empty[1] && v == max[1]) || (!empty[2] && v == max[2]) || (!empty[3] && v == max[3]) {\n\t\t\tcontinue\n\t\t}\n\t\tif empty[1] || v > max[1] {\n\t\t\tmax[3] = max[2]\n\t\t\tmax[2] = max[1]\n\t\t\tmax[1] = v\n\n\t\t\tif !empty[2] {\n\t\t\t\tempty[3] = false\n\t\t\t}\n\t\t\tif !empty[1] {\n\t\t\t\tempty[2] = false\n\t\t\t}\n\t\t\tempty[1] = false\n\t\t} else if empty[2] || v > max[2] {\n\t\t\tmax[3] = max[2]\n\t\t\tmax[2] = v\n\n\t\t\tif !empty[2] {\n\t\t\t\tempty[3] = false\n\t\t\t}\n\t\t\tempty[2] = false\n\t\t} else if empty[3] || v > max[3] {\n\t\t\tmax[3] = v\n\n\t\t\tempty[3] = false\n\t\t}\n\t}\n\n\tif !empty[3] {\n\t\treturn max[3]\n\t} else {\n\t\treturn max[1]\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/414/ac414_test.go",
    "content": "package problem414\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_thirdMax(t *testing.T) {\n\tnum1 := []int{3, 2, 1}\n\tnum2 := []int{2, 1}\n\tnum3 := []int{2, 3, 2, 1}\n\n\tfmt.Println(thirdMax(num1))\n\tfmt.Println(thirdMax(num2))\n\tfmt.Println(thirdMax(num3))\n}\n"
  },
  {
    "path": "algorithm/leetcode/415/ac415.go",
    "content": "package problem415\n\nfunc addStrings(num1 string, num2 string) string {\n\tstr1 := []rune(num1)\n\tstr2 := []rune(num2)\n\tans := make([]rune, 0)\n\tvar carry rune = 0\n\tfor i, j := len(str1)-1, len(str2)-1; i >= 0 || j >= 0 || 1 == carry; i, j = i-1, j-1 {\n\t\tvar x, y rune = 0, 0\n\t\tif i >= 0 {\n\t\t\tx = str1[i] - '0'\n\t\t}\n\t\tif j >= 0 {\n\t\t\ty = str2[j] - '0'\n\t\t}\n\t\tbit := (x+y+carry)%rune(10) + '0'\n\t\tcarry = (x + y + carry) / rune(10)\n\t\tans = append(ans, bit)\n\t}\n\n\tfor i, j := 0, len(ans)-1; i < j; {\n\t\tans[i], ans[j] = ans[j], ans[i]\n\t\ti++\n\t\tj--\n\t}\n\treturn string(ans)\n}\n\nfunc addStrings2(num1 string, num2 string) string {\n\tans := make([]byte, 0)\n\tcarry := byte(0)\n\tfor i, j := len(num1)-1, len(num2)-1; i >= 0 || j >= 0 || byte(1) == carry; i, j = i-1, j-1 {\n\t\tvar x, y byte\n\t\tif i >= 0 {\n\t\t\tx = num1[i] - '0'\n\t\t}\n\t\tif j >= 0 {\n\t\t\ty = num2[j] - '0'\n\t\t}\n\t\tbit := (x+y+carry)%10 + '0'\n\t\tcarry = (x + y + carry) / 10\n\t\tans = append(ans, bit)\n\t}\n\n\tfor i, j := 0, len(ans)-1; i < j; {\n\t\tans[i], ans[j] = ans[j], ans[i]\n\t\ti++\n\t\tj--\n\t}\n\treturn string(ans)\n}\n"
  },
  {
    "path": "algorithm/leetcode/415/ac415_test.go",
    "content": "package problem415\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_addStrings(t *testing.T) {\n\tstr1 := \"123\"\n\tstr2 := \"231\"\n\n\tfmt.Println(addStrings(str1, str2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/434/ac434.go",
    "content": "package problem434\n\nfunc countSegments(s string) int {\n\tans := 0\n\tfor i := 0; i < len(s); i++ {\n\t\tif s[i] != ' ' && (0 == i || ' ' == s[i-1]) {\n\t\t\tans++\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/437/ac437.go",
    "content": "package problem437\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc pathSum(root *TreeNode, sum int) int {\n\tif nil == root {\n\t\treturn 0\n\t}\n\treturn pathSumFrom(root, sum) + pathSum(root.Left, sum) + pathSum(root.Right, sum)\n}\n\nfunc pathSumFrom(node *TreeNode, sum int) int {\n\tif nil == node {\n\t\treturn 0\n\t}\n\n\tans := 0\n\tif node.Val == sum {\n\t\tans = 1\n\t}\n\treturn ans + pathSumFrom(node.Left, sum-node.Val) + pathSumFrom(node.Right, sum-node.Val)\n}\n"
  },
  {
    "path": "algorithm/leetcode/438/ac438.go",
    "content": "package problem438\n\nfunc findAnagrams(s string, p string) []int {\n\tdict := make(map[byte]int, 0)\n\tfor i := 0; i < len(p); i++ {\n\t\tdict[p[i]]++\n\t}\n\n\tans := make([]int, 0)\n\t//two points, initialize count to p's length\n\tleft, right, count := 0, 0, len(p)\n\tfor right < len(s) {\n\t\t//move right everytime, if the character exists in p's hash, decrease the count\n\t\t//current hash value >= 1 means the character is existing in p\n\t\tif dict[s[right]] >= 1 {\n\t\t\tcount--\n\t\t}\n\t\tdict[s[right]]--\n\t\tright++\n\n\t\t//when the count is down to 0, means we found the right anagram\n\t\t//then add window's left to result list\n\t\tif 0 == count {\n\t\t\tans = append(ans, left)\n\t\t}\n\n\t\t//if we find the window's size equals to p, then we have to move left (narrow the window) to find the new match window\n\t\t//++ to reset the hash because we kicked out the left\n\t\t//only increase the count if the character is in p\n\t\t//the count >= 0 indicate it was original in the hash, cuz it won't go below 0\n\t\tif right-left == len(p) {\n\t\t\tif v, ok := dict[s[left]]; ok && v >= 0 {\n\t\t\t\tcount++\n\t\t\t}\n\t\t\tdict[s[left]]++\n\t\t\tleft++\n\t\t}\n\t}\n\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/438/ac438_test.go",
    "content": "package problem438\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findAnagrams(t *testing.T) {\n\ts := \"cbaebabacd\"\n\tp := \"abc\"\n\n\tfmt.Println(findAnagrams(s, p))\n\n\ts1 := \"abab\"\n\tp1 := \"ab\"\n\tfmt.Println(findAnagrams(s1, p1))\n\n\ts2 := \"ababababab\"\n\tp2 := \"aab\"\n\tfmt.Println(findAnagrams(s2, p2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/441/ac441.go",
    "content": "package problem441\n\nimport \"math\"\n\n// 题目的意思其实就是从1~x层完整楼梯硬币数量加起来，要小于等于n，求最大的x。\n// 说到加起来的数量，很容易想到求累加和，我们知道求累加和的公式为：\n// sum = (1+x)*x/2\n// 这里就是要求 sum <= n 了。我们反过来求层数x。如果直接开方来求会存在错误，必须因式分解求得准确的x值：\n//\n// (1+x)*x/2 <= n\n// x*x + x <= 2*n\n// 4*x*x + 4*x <= 8*n\n// (2*x + 1)*(2*x + 1) - 1 <= 8*n\n// x <= (sqrt(8*n + 1) - 1) / 2\n\nfunc arrangeCoins(n int) int {\n\treturn int((math.Sqrt(float64(8*n+1)) - 1) / 2)\n}\n"
  },
  {
    "path": "algorithm/leetcode/441/ac441_test.go",
    "content": "package problem441\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_arrangeCoins(t *testing.T) {\n\tfmt.Println(arrangeCoins(5))\n\tfmt.Println(arrangeCoins(8))\n}\n"
  },
  {
    "path": "algorithm/leetcode/443/ac443.go",
    "content": "package problem443\n\nimport \"strconv\"\n\nfunc compress(chars []byte) int {\n\tindex, indexAns := 0, 0\n\tfor index < len(chars) {\n\t\tcurrentChar := chars[index]\n\t\tcount := 0\n\t\tfor index < len(chars) && chars[index] == currentChar {\n\t\t\tindex++\n\t\t\tcount++\n\t\t}\n\t\tchars[indexAns] = currentChar\n\t\tindexAns++\n\t\tif 1 != count {\n\t\t\tfor _, v := range []byte(strconv.Itoa(count)) {\n\t\t\t\tchars[indexAns] = v\n\t\t\t\tindexAns++\n\t\t\t}\n\t\t}\n\t}\n\treturn indexAns\n}\n"
  },
  {
    "path": "algorithm/leetcode/443/ac443_test.go",
    "content": "package problem443\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_compress(t *testing.T) {\n\tdata := []byte{'a', 'a', 'b', 'b', 'c', 'c', 'c'}\n\tfmt.Println(compress(data))\n}\n"
  },
  {
    "path": "algorithm/leetcode/447/ac447.go",
    "content": "package problem447\n\nfunc numberOfBoomerangs(points [][]int) int {\n\tans := 0\n\n\tfor i := 0; i < len(points); i++ {\n\t\tdict := make(map[int]int, 0)\n\t\tfor j := 0; j < len(points); j++ {\n\t\t\tif i == j {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\td := getDistance(points[i], points[j])\n\t\t\tdict[d]++\n\t\t}\n\n\t\tfor _, v := range dict {\n\t\t\tans += v * (v - 1)\n\t\t}\n\t}\n\n\treturn ans\n}\n\nfunc getDistance(a, b []int) int {\n\tdx := a[0] - b[0]\n\tdy := a[1] - b[1]\n\n\treturn dx*dx + dy*dy\n}\n"
  },
  {
    "path": "algorithm/leetcode/448/ac448.go",
    "content": "package problem448\n\nfunc findDisappearedNumbers(nums []int) []int {\n\tans := make([]int, 0)\n\n\tfor i := 0; i < len(nums); i++ {\n\t\tid := abs(nums[i]) - 1\n\t\tif nums[id] > 0 {\n\t\t\tnums[id] = -nums[id]\n\t\t}\n\t}\n\n\tfor i := 0; i < len(nums); i++ {\n\t\tif nums[i] > 0 {\n\t\t\tans = append(ans, i+1)\n\t\t}\n\t}\n\treturn ans\n}\n\nfunc abs(n int) int {\n\tif n < 0 {\n\t\tn = -n\n\t}\n\treturn n\n}\n"
  },
  {
    "path": "algorithm/leetcode/453/ac453.go",
    "content": "package problem453\n\nfunc minMoves(nums []int) int {\n\tif nil == nums || len(nums) == 0 {\n\t\treturn -1\n\t}\n\tif len(nums) == 1 {\n\t\treturn 0\n\t}\n\n\tminNumber := nums[0]\n\tsum := nums[0]\n\n\tfor i := 1; i < len(nums); i++ {\n\t\tsum += nums[i]\n\t\tif nums[i] < minNumber {\n\t\t\tminNumber = nums[i]\n\t\t}\n\t}\n\n\treturn sum - minNumber*len(nums)\n}\n"
  },
  {
    "path": "algorithm/leetcode/453/ac453_test.go",
    "content": "package problem453\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_minMoves(t *testing.T) {\n\tnum := []int{1, 2, 3}\n\n\tfmt.Println(minMoves(num))\n}\n"
  },
  {
    "path": "algorithm/leetcode/455/ac455.go",
    "content": "package problem455\n\nimport \"sort\"\n\nfunc findContentChildren(g []int, s []int) int {\n\tsort.Ints(g)\n\tsort.Ints(s)\n\n\ti := 0\n\tfor j := 0; i < len(g) && j < len(s); j++ {\n\t\tif g[i] <= s[j] {\n\t\t\ti++\n\t\t}\n\t}\n\treturn i\n}\n"
  },
  {
    "path": "algorithm/leetcode/455/ac455_test.go",
    "content": "package problem455\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findContentChildren(t *testing.T) {\n\tg1 := []int{1, 2, 3}\n\ts1 := []int{1, 1}\n\n\tfmt.Println(findContentChildren(g1, s1))\n\n\tg2 := []int{1, 2}\n\ts2 := []int{1, 2, 3}\n\tfmt.Println(findContentChildren(g2, s2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/458/ac458.go",
    "content": "package problem458\n\n// 1. 一只猪在一小时内最多能验多少桶？\n//\n//一次喝一个桶的，15分钟后没挂再喝第二桶，一小时60分钟内可以喝 60/15 = 4 次，如果有5桶水，那个只要喝前4桶就只能第5桶是否有毒。\n//\n//因此一只小猪在一小时可以验5桶水\n//\n//\n//2. 两只呢？\n//\n//既然一只能验5桶，那么用二维的思路，2只猪应该可以验5*5桶：\n//\n//猪A负责行，猪B负责列，每15分钟试喝一行/一列的所有5桶水，通过2只猪上天的时间能推断出毒水在几行几列。\n//\n//1   2   3   4   5\n//\n//6   7   8   9  10\n//\n//11 12 13 14 15\n//\n//16 17 18 19 20\n//\n//21 22 23 24 25\n//\n//\n//3. N只\n//\n//如此类推到N只的情况，使用N维去分区，则5^N >= 1000即为解决本题的公式。\n\nfunc poorPigs(buckets int, minutesToDie int, minutesToTest int) int {\n\tpigs := 0\n\tfor mypow(minutesToTest/minutesToDie+1, pigs) < buckets {\n\t\tpigs++\n\t}\n\treturn pigs\n}\n\nfunc mypow(a, b int) int {\n\tif 0 == b {\n\t\treturn 1\n\t}\n\tif 1 == b {\n\t\treturn a\n\t}\n\tif 0 == b&1 {\n\t\treturn mypow(a*a, b/2)\n\t} else {\n\t\treturn a * mypow(a*a, b/2)\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/459/ac459.go",
    "content": "package problem459\n\nimport \"strings\"\n\nfunc repeatedSubstringPattern(s string) bool {\n\tif len(s) < 2 {\n\t\treturn false\n\t}\n\n\tnewStr := s + s\n\treturn strings.Contains(newStr[1:len(newStr)-1], s)\n}\n"
  },
  {
    "path": "algorithm/leetcode/459/ac459_test.go",
    "content": "package problem459\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_repeatedSubstringPattern(t *testing.T) {\n\ts := \"ab\"\n\tfmt.Println(repeatedSubstringPattern(s))\n\n\ts2 := \"abab\"\n\tfmt.Println(repeatedSubstringPattern(s2))\n\n}\n"
  },
  {
    "path": "algorithm/leetcode/461/ac461.go",
    "content": "package problem461\n\nfunc hammingDistance(x int, y int) int {\n\tn := x ^ y\n\tans := 0\n\tfor n != 0 {\n\t\tn &= n - 1\n\t\tans++\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/463/ac463.go",
    "content": "package problem463\n\nfunc islandPerimeter(grid [][]int) int {\n\tisLand, neighbours := 0, 0\n\n\tfor i := 0; i < len(grid); i++ {\n\t\tfor j := 0; j < len(grid[i]); j++ {\n\t\t\tif 1 == grid[i][j] {\n\t\t\t\tisLand++\n\t\t\t\t// 统计下一行与该陆地块相邻的数量\n\t\t\t\tif i < len(grid)-1 && 1 == grid[i+1][j] {\n\t\t\t\t\tneighbours++\n\t\t\t\t}\n\t\t\t\t// 统计右侧与该陆地块相邻的数量\n\t\t\t\tif j < len(grid[i]) - 1 && 1 == grid[i][j+1] {\n\t\t\t\t\tneighbours++\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t// and the pattern is islands * 4 - neighbours * 2, since every adjacent islands made two sides disappeared\n\t// 4 + 4 - ? = 6  -> ? = 2\n\treturn isLand*4 - neighbours*2\n}\n"
  },
  {
    "path": "algorithm/leetcode/463/ac463_test.go",
    "content": "package problem463\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_islandPerimeter(t *testing.T) {\n\tland := [][]int{\n\t\t{0, 1, 0, 0},\n\t\t{1, 1, 1, 0},\n\t\t{0, 1, 0, 0},\n\t\t{1, 1, 0, 0}}\n\n\tfmt.Println(islandPerimeter(land))\n\n}\n"
  },
  {
    "path": "algorithm/leetcode/475/ac475.go",
    "content": "package problem475\n\nimport \"sort\"\n\nfunc findRadius(houses []int, heaters []int) int {\n\tsort.Ints(houses)\n\tsort.Ints(heaters)\n\n\ti, ans := 0, 0\n\tfor _, house := range houses {\n\t\tfor i < len(heaters)-1 && heaters[i]+heaters[i+1] <= house*2 {\n\t\t\ti++\n\t\t}\n\t\tans = maxInt(ans, absInt(heaters[i]-house))\n\t}\n\treturn ans\n}\n\nfunc maxInt(a, b int) int {\n\tif a >= b {\n\t\treturn a\n\t}\n\treturn b\n}\n\nfunc absInt(a int) int {\n\tif a < 0 {\n\t\treturn -a\n\t}\n\treturn a\n}\n"
  },
  {
    "path": "algorithm/leetcode/475/ac475_test.go",
    "content": "package problem475\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findRadius(t *testing.T) {\n\tfmt.Println(findRadius([]int{1, 2, 3}, []int{2}))\n\tfmt.Println(findRadius([]int{1, 2, 3, 4, 99}, []int{1, 4}))\n}\n"
  },
  {
    "path": "algorithm/leetcode/476/ac476.go",
    "content": "package problem476\n\nfunc findComplement(num int) int {\n\ttemp, mask := num, 0\n\n\tfor temp > 0 {\n\t\tmask = mask*2 + 1\n\t\ttemp /= 2\n\t}\n\treturn mask ^ num\n}\n"
  },
  {
    "path": "algorithm/leetcode/476/ac476_test.go",
    "content": "package problem476\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findComplement(t *testing.T) {\n\tfmt.Println(findComplement(5))\n}\n"
  },
  {
    "path": "algorithm/leetcode/479/ac479.go",
    "content": "package problem479\n\nimport (\n\t\"strconv\"\n\t\"math\"\n)\n\nfunc largestPalindrome(n int) int {\n\tif 1 == n {\n\t\treturn 9\n\t}\n\n\tmax := int(math.Pow10(n) - 1)\n\tfor v := max - 1; v > max/10; v-- {\n\t\tu, _ := strconv.Atoi(strconv.Itoa(v) + reverseInt(v))\n\t\tfor x := max; x*x >= u; x-- {\n\t\t\tif u%x == 0 {\n\t\t\t\treturn u % 1337\n\t\t\t}\n\t\t}\n\t}\n\treturn 0\n}\n\nfunc reverseInt(a int) string {\n\ttemp := []byte(strconv.Itoa(a))\n\tfor i, j := 0, len(temp)-1; i < j; i, j = i+1, j-1 {\n\t\ttemp[i], temp[j] = temp[j], temp[i]\n\t}\n\treturn string(temp)\n}\n"
  },
  {
    "path": "algorithm/leetcode/479/ac479_test.go",
    "content": "package problem479\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_largestPalindrome(t *testing.T) {\n\tfmt.Println(largestPalindrome(2))\n\tfmt.Println(largestPalindrome(3))\n\tfmt.Println(largestPalindrome(4))\n}\n"
  },
  {
    "path": "algorithm/leetcode/485/ac485.go",
    "content": "package problem485\n\nfunc findMaxConsecutiveOnes(nums []int) int {\n\tans, count := 0, 0\n\tfor _, v := range nums {\n\t\tif 1 == v {\n\t\t\tcount++\n\t\t\tif ans < count {\n\t\t\t\tans = count\n\t\t\t}\n\t\t} else {\n\t\t\tcount = 0\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/485/ac485_test.go",
    "content": "package problem485\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findMaxConsecutiveOnes(t *testing.T) {\n\tnums := []int{1, 1, 0, 1, 1, 1}\n\n\tfmt.Println(findMaxConsecutiveOnes(nums))\n}\n"
  },
  {
    "path": "algorithm/leetcode/492/ac492.go",
    "content": "package problem492\n\nimport \"math\"\n\nfunc constructRectangle(area int) []int {\n\tans := make([]int, 0)\n\n\tnum := int(math.Sqrt(float64(area)))\n\tfor num > 0 {\n\t\tif area%num == 0 {\n\t\t\t// L W 需要按顺排列并确保 L >= W\n\t\t\tif num >= area/num {\n\t\t\t\tans = append(ans, num, area/num)\n\t\t\t} else {\n\t\t\t\tans = append(ans, area/num, num)\n\t\t\t}\n\t\t\tbreak\n\t\t} else {\n\t\t\tnum--\n\t\t}\n\t}\n\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/492/ac492_test.go",
    "content": "package problem492\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_constructRectangle(t *testing.T) {\n\tfmt.Println(constructRectangle(4))\n}\n"
  },
  {
    "path": "algorithm/leetcode/496/ac496.go",
    "content": "package problem496\n\nfunc nextGreaterElement(findNums []int, nums []int) []int {\n\tans := make([]int, 0)\n\tfor _, v := range findNums {\n\t\tans = append(ans, nextMax(v, nums))\n\t}\n\treturn ans\n}\n\nfunc nextMax(n int, nums []int) int {\n\tans := -1\n\tindex := 0\n\n\t// 找到数字 n 在 nums 切片中的位置\n\tfor index < len(nums) && nums[index] != n {\n\t\tindex++\n\t}\n\n\tfor index < len(nums) {\n\t\tif nums[index] > n {\n\t\t\tans = nums[index]\n\t\t\tbreak\n\t\t}\n\t\tindex++\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/496/ac496_test.go",
    "content": "package problem496\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_nextGreaterElement(t *testing.T) {\n\tnum1 := []int{4, 1, 2}\n\tnum2 := []int{1, 3, 4, 2}\n\n\tfmt.Println(nextGreaterElement(num1, num2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/500/ac500.go",
    "content": "package problem500\n\nimport \"strings\"\n\nfunc findWords(words []string) []string {\n\tans := make([]string, 0)\n\tdata := []string{\"qwertyuiop\", \"asdfghjkl\", \"zxcvbnm\"}\n\n\tfor _, v := range words {\n\t\tword := strings.ToLower(v)\n\t\tif (strings.ContainsAny(data[0], word) && !strings.ContainsAny(data[1], word) && !strings.ContainsAny(data[2], word)) ||\n\t\t\t(!strings.ContainsAny(data[0], word) && strings.ContainsAny(data[1], word) && !strings.ContainsAny(data[2], word)) ||\n\t\t\t(!strings.ContainsAny(data[0], word) && !strings.ContainsAny(data[1], word) && strings.ContainsAny(data[2], word)) {\n\t\t\tans = append(ans, v)\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/500/ac500_test.go",
    "content": "package problem500\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findWords(t *testing.T) {\n\twords := []string{\"Hello\", \"Alaska\", \"Dad\", \"Peace\"}\n\tfmt.Println(findWords(words))\n}\n"
  },
  {
    "path": "algorithm/leetcode/501/ac501.go",
    "content": "package problem501\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc findMode(root *TreeNode) []int {\n\tans := make([]int, 0)\n\tif nil == root {\n\t\treturn ans\n\t}\n\n\tmax, count, pre := 1, 0, root.Val\n\ttraverse(root, &ans, &max, &count, &pre)\n\treturn ans\n}\n\nfunc traverse(root *TreeNode, ans *[]int, max, count, pre *int) {\n\tif nil == root {\n\t\treturn\n\t}\n\n\ttraverse(root.Left, ans, max, count, pre)\n\n\tif root.Val == *pre {\n\t\t*count++\n\t\tif *count == *max {\n\t\t\t*ans = append(*ans, root.Val)\n\t\t} else if *count > *max {\n\t\t\t*max = *count\n\t\t\t*ans = (*ans)[:0]\n\t\t\t*ans = append(*ans, root.Val)\n\t\t}\n\t} else {\n\t\t*count = 1\n\t\tif *count == *max {\n\t\t\t*ans = append(*ans, root.Val)\n\t\t}\n\t}\n\t*pre = root.Val\n\n\ttraverse(root.Right, ans, max, count, pre)\n\n}\n"
  },
  {
    "path": "algorithm/leetcode/501/ac501_test.go",
    "content": "package problem501\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findMode(t *testing.T) {\n\tnode21 := TreeNode{Val: 2, Left: nil, Right: nil}\n\tnode2 := TreeNode{Val: 2, Left: &node21, Right: nil}\n\tnode1 := TreeNode{Val: 1, Left: nil, Right: &node2}\n\n\tfmt.Println(findMode(&node1))\n}\n"
  },
  {
    "path": "algorithm/leetcode/504/ac504.go",
    "content": "package problem504\n\nimport (\n\t\"strconv\"\n)\n\nfunc convertToBase7(num int) string {\n\tif 0 == num {\n\t\treturn \"0\"\n\t}\n\n\tans := \"\"\n\tneg := false\n\tif num < 0 {\n\t\tnum = -num\n\t\tneg = true\n\t}\n\n\tfor 0 != num {\n\t\tans = strconv.Itoa(num%7) + ans\n\t\tnum /= 7\n\t}\n\n\tif neg {\n\t\tans = \"-\" + ans\n\t}\n\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/504/ac504_test.go",
    "content": "package problem504\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_convertToBase7(t *testing.T) {\n\tfmt.Println(convertToBase7(7))\n\tfmt.Println(convertToBase7(-7))\n\tfmt.Println(convertToBase7(100))\n}\n"
  },
  {
    "path": "algorithm/leetcode/506/ac506.go",
    "content": "package problem506\n\nimport (\n\t\"sort\"\n\t\"strconv\"\n)\n\ntype person struct {\n\tscore int\n\tindex int\n}\n\ntype persons []person\n\n// Len方法返回集合中的元素个数\nfunc (p persons) Len() int {\n\treturn len(p)\n}\n\n// Less方法报告索引i的元素是否比索引j的元素小\nfunc (p persons) Less(i, j int) bool {\n\t// 此处实现从大到小排序 (大的数字在前，小的在后)\n\treturn p[i].score > p[j].score\n}\n\n// Swap方法交换索引i和j的两个元素\nfunc (p persons) Swap(i, j int) {\n\tp[i], p[j] = p[j], p[i]\n}\n\nfunc findRelativeRanks(nums []int) []string {\n\tans := make([]string, len(nums))\n\n\tps := make(persons, len(nums))\n\tfor i, v := range nums {\n\t\tps[i].score = v\n\t\tps[i].index = i\n\t}\n\n\tsort.Sort(ps)\n\n\tfor i, v := range ps {\n\t\tswitch i {\n\t\tcase 0:\n\t\t\tans[v.index] = \"Gold Medal\"\n\t\tcase 1:\n\t\t\tans[v.index] = \"Silver Medal\"\n\t\tcase 2:\n\t\t\tans[v.index] = \"Bronze Medal\"\n\t\tdefault:\n\t\t\tans[v.index] = strconv.Itoa(i + 1)\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/506/ac506_test.go",
    "content": "package problem506\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findRelativeRanks(t *testing.T) {\n\tnums := []int{5, 4, 3, 2, 1}\n\n\tfmt.Println(findRelativeRanks(nums))\n}\n"
  },
  {
    "path": "algorithm/leetcode/507/ac507.go",
    "content": "package problem507\n\nimport \"math\"\n\nfunc checkPerfectNumber(num int) bool {\n\tif 1 == num {\n\t\treturn false\n\t}\n\n\t// 1 为该数字的正因子，需要计入\n\tsum := 1\n\tfor i := 2; i <= int(math.Sqrt(float64(num))); i++ {\n\t\tif 0 == num%i {\n\t\t\tsum += i + num/i\n\t\t}\n\t}\n\n\treturn sum == num\n}\n"
  },
  {
    "path": "algorithm/leetcode/507/ac507_test.go",
    "content": "package problem507\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_checkPerfectNumber(t *testing.T) {\n\tfmt.Println(checkPerfectNumber(6))\n\tfmt.Println(checkPerfectNumber(28))\n\tfmt.Println(checkPerfectNumber(30))\n}\n"
  },
  {
    "path": "algorithm/leetcode/520/ac520.go",
    "content": "package problem520\n\nfunc detectCapitalUse(word string) bool {\n\tif len(word) <= 1 {\n\t\treturn true\n\t}\n\n\tfirstChar := word[0]\n\tsecondChar := word[1]\n\tif 'a' <= firstChar && firstChar <= 'z' {\n\t\tfor i := 1; i < len(word); i++ {\n\t\t\tif word[i] < 'a' || word[i] > 'z' {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t} else if 'a' <= secondChar && secondChar <= 'z' {\n\t\tfor i := 2; i < len(word); i++ {\n\t\t\tif word[i] < 'a' || word[i] > 'z' {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor i := 1; i < len(word); i++ {\n\t\t\tif word[i] < 'A' || word[i] > 'Z' {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t}\n\treturn true\n}\n\n// 直接检测单词中大写字母的数量\n// 符合规范的有下面几种情况：\n// 1. 全部都是大写单词 -> 大写单词数目 = 单词长度\n// 2. 没有大写单词 -> 大写单词数目 = 0\n// 3. 只有头部是大写单词 -> 大写单词数目 = 1 && 仅头部第一个单词是大写\nfunc detectCapitalUse2(word string) bool {\n\tif len(word) <= 1 {\n\t\treturn true\n\t}\n\n\tcount := 0\n\tfor i := 0; i < len(word); i++ {\n\t\tif word[i] < 'a' {\n\t\t\tcount++\n\t\t}\n\t}\n\n\tif 0 == count || len(word) == count || (1 == count && word[0] < 'a') {\n\t\treturn true\n\t}\n\treturn false\n}\n"
  },
  {
    "path": "algorithm/leetcode/520/ac520_test.go",
    "content": "package problem520\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_detectCapitalUse(t *testing.T) {\n\tstr1 := \"USA\"\n\tfmt.Println(detectCapitalUse(str1))\n\n\tstr2 := \"Leetcode\"\n\tfmt.Println(detectCapitalUse(str2))\n\n\tstr3 := \"LEETcode\"\n\tfmt.Println(detectCapitalUse(str3))\n\n\tfmt.Println(detectCapitalUse2(str1))\n\tfmt.Println(detectCapitalUse2(str2))\n\tfmt.Println(detectCapitalUse2(str3))\n}\n"
  },
  {
    "path": "algorithm/leetcode/521/ac521.go",
    "content": "package problem521\n\nfunc findLUSlength(a string, b string) int {\n\tif a == b {\n\t\treturn -1\n\t}\n\n\tif len(a) > len(b) {\n\t\treturn len(a)\n\t}\n\treturn len(b)\n}\n"
  },
  {
    "path": "algorithm/leetcode/530/ac530.go",
    "content": "package problem530\n\nimport \"math\"\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc getMinimumDifference(root *TreeNode) int {\n\tnumbers := []int{math.MaxInt32, -1}\n\n\tif nil == root {\n\t\treturn numbers[0]\n\t}\n\tcore(root, numbers)\n\treturn numbers[0]\n}\n\nfunc core(root *TreeNode, nums []int) int {\n\tif nil == root {\n\t\treturn nums[0]\n\t}\n\n\tcore(root.Left, nums)\n\n\tif -1 != nums[1] {\n\t\tnums[0] = myMin(nums[0], root.Val-nums[1])\n\t}\n\tnums[1] = root.Val\n\n\tcore(root.Right, nums)\n\treturn nums[0]\n}\n\nfunc myMin(a, b int) int {\n\tif a < b {\n\t\treturn a\n\t}\n\treturn b\n}\n"
  },
  {
    "path": "algorithm/leetcode/530/ac530_test.go",
    "content": "package problem530\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_getMinimumDifference(t *testing.T) {\n\tnode3 := TreeNode{Val: 3, Left: nil, Right: nil}\n\tnode5 := TreeNode{Val: 5, Left: &node3, Right: nil}\n\tnode1 := TreeNode{Val: 1, Left: nil, Right: &node5}\n\n\tfmt.Println(getMinimumDifference(&node1))\n\n}\n"
  },
  {
    "path": "algorithm/leetcode/532/ac532.go",
    "content": "package problem532\n\nfunc findPairs(nums []int, k int) int {\n\tif nil == nums || len(nums) == 0 || k < 0 {\n\t\treturn 0\n\t}\n\n\tdict := make(map[int]int, 0)\n\tfor _, v := range nums {\n\t\tdict[v]++\n\t}\n\n\tans := 0\n\tfor key, value := range dict {\n\t\tif 0 == k {\n\t\t\tif value >= 2 {\n\t\t\t\tans++\n\t\t\t}\n\t\t} else {\n\t\t\tif _, ok := dict[key+k]; ok {\n\t\t\t\tans++\n\t\t\t}\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/532/ac532_test.go",
    "content": "package problem532\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findPairs(t *testing.T) {\n\tnums := []int{3, 1, 4, 1, 5}\n\tfmt.Println(findPairs(nums, 2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/538/ac538.go",
    "content": "package problem538\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc convertBST(root *TreeNode) *TreeNode {\n\tif nil == root {\n\t\treturn root\n\t}\n\n\tsums := 0\n\tconvertBSTCore(root, &sums)\n\treturn root\n}\n\nfunc convertBSTCore(root *TreeNode, sums *int) {\n\tif nil == root {\n\t\treturn\n\t}\n\n\tconvertBSTCore(root.Right, sums)\n\n\troot.Val += *sums\n\t*sums = root.Val\n\n\tconvertBSTCore(root.Left, sums)\n}\n"
  },
  {
    "path": "algorithm/leetcode/541/ac541.go",
    "content": "package problem541\n\nfunc reverseStr(s string, k int) string {\n\tchars := []byte(s)\n\n\tfor idx := 0; idx*k < len(chars); idx += 2 {\n\t\tstart, end := idx*k, idx*k+k-1\n\t\tif end >= len(chars) {\n\t\t\tend = len(chars)-1\n\t\t}\n\n\t\tfor start < end {\n\t\t\tchars[start], chars[end] = chars[end], chars[start]\n\t\t\tstart++\n\t\t\tend--\n\t\t}\n\t}\n\treturn string(chars)\n}\n"
  },
  {
    "path": "algorithm/leetcode/541/ac541_test.go",
    "content": "package problem541\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_reverseStr(t *testing.T) {\n\ts := \"abcdefg\"\n\tk := 2\n\n\tfmt.Println(reverseStr(s, k))\n\n\ts1 := \"a\"\n\tk1 := 2\n\tfmt.Println(reverseStr(s1, k1))\n}\n"
  },
  {
    "path": "algorithm/leetcode/543/ac543.go",
    "content": "package problem543\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\n// 二叉树的直径解题思路:\n// 二叉树中的某个节点的左子树深度 与 该节点的右子树深度 之和为树种最大值，则该最大值即为二叉树的直径。\nfunc diameterOfBinaryTree(root *TreeNode) int {\n\tans := 0\n\tif nil == root {\n\t\treturn ans\n\t}\n\n\tleft := depthOfTree(root.Left, &ans)\n\tright := depthOfTree(root.Right, &ans)\n\tif left+right > ans {\n\t\tans = left + right\n\t}\n\n\treturn ans\n}\n\nfunc depthOfTree(node *TreeNode, diameter *int) int {\n\tif nil == node {\n\t\treturn 0\n\t}\n\n\tleftDepth := depthOfTree(node.Left, diameter)\n\trightDepth := depthOfTree(node.Right, diameter)\n\ttemp := leftDepth + rightDepth\n\tif temp > *diameter {\n\t\t*diameter = temp\n\t}\n\n\treturn myMax(leftDepth, rightDepth) + 1\n}\n\nfunc myMax(a, b int) int {\n\tif a >= b {\n\t\treturn a\n\t}\n\treturn b\n}\n"
  },
  {
    "path": "algorithm/leetcode/551/ac551.go",
    "content": "package problem551\n\nimport \"strings\"\n\nfunc checkRecord(s string) bool {\n\tcountA := 0\n\n\tfor i := 0; i < len(s); i++ {\n\t\tif s[i] == 'A' {\n\t\t\tcountA++\n\t\t}\n\t\tif s[i] == 'L' {\n\t\t\tif i+2 < len(s) && s[i+1] == 'L' && s[i+2] == 'L' {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t}\n\n\tif countA > 1 {\n\t\treturn false\n\t}\n\treturn true\n}\n\nfunc checkRecord2(s string) bool {\n\treturn strings.IndexByte(s, 'A') == strings.LastIndexByte(s, 'A') && !strings.Contains(s, \"LLL\")\n}\n"
  },
  {
    "path": "algorithm/leetcode/551/ac551_test.go",
    "content": "package problem551\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_checkRecord(t *testing.T) {\n\tstr1 := \"PPALLP\"\n\tfmt.Println(checkRecord(str1))\n\n\tstr2 := \"PPALLL\"\n\tfmt.Println(checkRecord(str2))\n\n}\n"
  },
  {
    "path": "algorithm/leetcode/557/ac557.go",
    "content": "package problem557\n\nfunc reverseWords(s string) string {\n\tstrChar := []rune(s)\n\n\tstart, end := 0, 0\n\tfor i := 0; i < len(s); i++ {\n\t\tif s[i] == ' ' {\n\t\t\tend = i - 1\n\t\t\treverse(strChar, start, end)\n\t\t\tstart = i + 1\n\t\t}\n\t}\n\tend = len(s)-1\n\treverse(strChar, start, end)\n\treturn string(strChar)\n}\n\nfunc reverse(chars []rune, start, end int) {\n\tfor start < end {\n\t\tchars[start], chars[end] = chars[end], chars[start]\n\t\tstart++\n\t\tend--\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/557/ac557_test.go",
    "content": "package problem557\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_reverseWords(t *testing.T) {\n\tstr := \"Let's take LeetCode contest\"\n\tfmt.Println(reverseWords(str))\n}\n"
  },
  {
    "path": "algorithm/leetcode/561/ac561.go",
    "content": "package problem561\n\nimport \"sort\"\n\nfunc arrayPairSum(nums []int) int {\n\tans := 0\n\tsort.Ints(nums)\n\tfor i, value := range nums {\n\t\tif 0 == i%2 {\n\t\t\tans += value\n\t\t}\n\t}\n\treturn ans\n}\n\nfunc arrayPairSum2(nums []int) int {\n\t//给数组排序，然后挨着的两个为一组，也就是取第1,3,....到2n-3,2n-1的和(从1开始计数)\n\tdict := make([]int, 20001)\n\t//考虑负数\n\tfor _, v := range nums {\n\t\tdict[v+10000]++\n\t}\n\n\tid, count := 0, 0\n\tfor k, v := range dict {\n\t\t//考虑有相同数据\n\t\tfor v > 0 {\n\t\t\tid++\n\t\t\tif 1 == id%2 {\n\t\t\t\tcount += k - 10000\n\t\t\t}\n\t\t\tv--\n\t\t}\n\t}\n\treturn count\n}\n"
  },
  {
    "path": "algorithm/leetcode/561/ac561_test.go",
    "content": "package problem561\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_arrayPairSum(t *testing.T) {\n\tnums := []int{1, 4, 3, 2}\n\n\tfmt.Println(arrayPairSum(nums))\n\n}\n"
  },
  {
    "path": "algorithm/leetcode/563/ac563.go",
    "content": "package problem563\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc findTilt(root *TreeNode) int {\n\tret := make([]int, 1)\n\thelper(root, ret)\n\treturn ret[0]\n}\n\nfunc helper(root *TreeNode, ret []int) int {\n\tif nil == root {\n\t\treturn 0\n\t}\n\n\tlSum := helper(root.Left, ret)\n\trSum := helper(root.Right, ret)\n\tret[0] += myAbs(lSum, rSum)\n\n\treturn lSum + rSum + root.Val\n}\n\nfunc myAbs(a, b int) int {\n\tif a < b {\n\t\treturn b - a\n\t}\n\treturn a - b\n}\n"
  },
  {
    "path": "algorithm/leetcode/566/ac566.go",
    "content": "package problem566\n\nfunc matrixReshape(nums [][]int, r int, c int) [][]int {\n\tif nil == nums || 0 == len(nums) || len(nums)*len(nums[0]) != r*c {\n\t\treturn nums\n\t}\n\n\ttemp := make([]int, 0)\n\tfor row := 0; row < len(nums); row++ {\n\t\tfor col := 0; col < len(nums[0]); col++ {\n\t\t\ttemp = append(temp, nums[row][col])\n\t\t}\n\t}\n\n\tans := make([][]int, r)\n\tfor row := 0; row < r; row++ {\n\t\ttmp := make([]int, c)\n\t\tfor col := 0; col < c; col++ {\n\t\t\ttmp[col] = temp[row*c+col]\n\t\t}\n\t\tans[row] = tmp\n\t}\n\treturn ans\n}\n\nfunc matrixReshape2(nums [][]int, r int, c int) [][]int {\n\tif nil == nums || 0 == len(nums) || len(nums)*len(nums[0]) != r*c {\n\t\treturn nums\n\t}\n\n\toriginCol := len(nums[0])\n\n\tans := make([][]int, r)\n\tfor row := 0; row < r; row++ {\n\t\ttemp := make([]int, c)\n\t\tfor col := 0; col < c; col++ {\n\t\t\tidx := row*c + col\n\t\t\tcurrentRow := idx / originCol\n\t\t\tcurrentCol := idx % originCol\n\t\t\ttemp[col] = nums[currentRow][currentCol]\n\t\t}\n\t\tans[row] = temp\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/566/ac566_test.go",
    "content": "package problem566\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_matrixReshape(t *testing.T) {\n\tnums := [][]int{\n\t\t{1, 2},\n\t\t{3, 4}}\n\n\tfmt.Println(matrixReshape(nums, 1, 4))\n\tfmt.Println(matrixReshape(nums, 2, 4))\n\n\tfmt.Println(matrixReshape2(nums, 1, 4))\n\tfmt.Println(matrixReshape2(nums, 2, 4))\n}\n"
  },
  {
    "path": "algorithm/leetcode/572/ac572.go",
    "content": "package problem572\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc isSubtree(s *TreeNode, t *TreeNode) bool {\n\tif nil == s || nil == t {\n\t\treturn s == t || nil == t\n\t}\n\n\treturn isSame(s, t) || isSubtree(s.Left, t) || isSubtree(s.Right, t)\n}\n\n// 从该节点起的 2 个子树是否完全相同\nfunc isSame(t1, t2 *TreeNode) bool {\n\tif nil == t1 || nil == t2 {\n\t\treturn t1 == t2\n\t}\n\n\treturn t1.Val == t2.Val && isSame(t1.Left, t2.Left) && isSame(t1.Right, t2.Right)\n}\n"
  },
  {
    "path": "algorithm/leetcode/575/ac575.go",
    "content": "package problem575\n\nfunc distributeCandies(candies []int) int {\n\tmySet := make(map[int]int, 0)\n\n\tfor _, v := range candies {\n\t\tmySet[v]++\n\t}\n\n\tif len(mySet) >= len(candies)/2 {\n\t\treturn len(candies) / 2\n\t}\n\treturn len(mySet)\n}\n"
  },
  {
    "path": "algorithm/leetcode/575/ac575_test.go",
    "content": "package problem575\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_distributeCandies(t *testing.T) {\n\tnums := []int{1, 1, 2, 2, 3, 3}\n\n\tfmt.Println(distributeCandies(nums))\n\n\tnums2 := []int{1, 1, 2, 3}\n\tfmt.Println(distributeCandies(nums2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/581/ac581.go",
    "content": "package problem581\n\nimport \"sort\"\n\nfunc findUnsortedSubarray(nums []int) int {\n\tif nil == nums || len(nums) == 0 {\n\t\treturn 0\n\t}\n\n\tnumsBackup := make([]int, len(nums))\n\tcopy(numsBackup, nums)\n\tsort.Ints(nums)\n\tleft, right := 0, len(nums)-1\n\tfor ; left < len(nums) && nums[left] == numsBackup[left]; {\n\t\tleft++\n\t}\n\t// 该数组是有序数组\n\tif left == len(nums) {\n\t\treturn 0\n\t}\n\n\tfor ; right >= 0 && nums[right] == numsBackup[right]; {\n\t\tright--\n\t}\n\treturn right - left + 1\n}\n\nfunc findUnsortedSubarray2(nums []int) int {\n\tif nil == nums || len(nums) == 0 {\n\t\treturn 0\n\t}\n\n\tn := len(nums)\n\tbegin, end := -1, -2\n\tmin, max := nums[n-1], nums[0]\n\tfor i := 1; i < n; i++ {\n\t\tmax = myMax(max, nums[i])\n\t\tmin = myMin(min, nums[n-1-i])\n\t\tif nums[i] < max {\n\t\t\tend = i\n\t\t}\n\t\tif nums[n-1-i] > min {\n\t\t\tbegin = n - 1 - i\n\t\t}\n\t}\n\treturn end - begin + 1\n}\n\nfunc myMax(a, b int) int {\n\tif a >= b {\n\t\treturn a\n\t}\n\treturn b\n}\n\nfunc myMin(a, b int) int {\n\tif a <= b {\n\t\treturn a\n\t}\n\treturn b\n}\n"
  },
  {
    "path": "algorithm/leetcode/581/ac581_test.go",
    "content": "package problem581\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findUnsortedSubarray(t *testing.T) {\n\tnum := []int{2, 6, 4, 8, 10, 9, 15}\n\tnum2 := []int{1, 2, 3, 4}\n\n\tfmt.Println(findUnsortedSubarray(num))\n\tfmt.Println(findUnsortedSubarray(num2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/594/ac594.go",
    "content": "package problem594\n\n// 和谐数组为 原数组的子数组即可，不需要是连续的子数组...\nfunc findLHS(nums []int) int {\n\tdict := make(map[int]int, 0)\n\tfor _, v := range nums {\n\t\tdict[v]++\n\t}\n\n\tans := 0\n\tfor k, v := range dict {\n\t\tif _, ok := dict[k+1]; ok {\n\t\t\tans = myMax(ans, v+dict[k+1])\n\t\t}\n\t}\n\treturn ans\n}\n\nfunc myMax(a, b int) int {\n\tif a >= b {\n\t\treturn a\n\t}\n\treturn b\n}\n"
  },
  {
    "path": "algorithm/leetcode/594/ac594_test.go",
    "content": "package problem594\n\nimport (\n\t\"fmt\"\n\t\"testing\"\n)\n\nfunc Test_findLHS(t *testing.T) {\n\tnums := []int{1, 3, 2, 2, 5, 2, 3, 7}\n\tfmt.Println(findLHS(nums))\n\n\tnums2 := []int{2, 2, 2, 9, 3, 3, 3}\n\tfmt.Println(findLHS(nums2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/598/ac598.go",
    "content": "package problem598\n\nfunc maxCount(m int, n int, ops [][]int) int {\n\tif nil == ops || len(ops) == 0 {\n\t\treturn m * n\n\t}\n\n\trow, col := ops[0][0], ops[0][1]\n\tfor _, v := range ops {\n\t\trow = myMin(row, v[0])\n\t\tcol = myMin(col, v[1])\n\t}\n\treturn row * col\n}\n\nfunc myMin(a, b int) int {\n\tif a <= b {\n\t\treturn a\n\t}\n\treturn b\n}\n"
  },
  {
    "path": "algorithm/leetcode/598/ac598_test.go",
    "content": "package problem598\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_maxCount(t *testing.T) {\n\tope := [][]int{\n\t\t{2, 2},\n\t\t{3, 3}}\n\n\tfmt.Println(maxCount(3, 3, ope))\n}\n"
  },
  {
    "path": "algorithm/leetcode/599/ac599.go",
    "content": "package problem599\n\nfunc findRestaurant(list1 []string, list2 []string) []string {\n\tdict1 := make(map[string]int, len(list1))\n\tdict2 := make(map[string]int, len(list2))\n\n\tfor id, v := range list1 {\n\t\tdict1[v] = id + 1\n\t}\n\tfor id, v := range list2 {\n\t\tdict2[v] = id + 1\n\t}\n\n\tans := make([]string, 0)\n\tmin := 2001\n\tfor k, v := range dict1 {\n\t\tif v2, ok := dict2[k]; ok && v+v2 <= min {\n\t\t\tif v+v2 < min {\n\t\t\t\tmin = v + v2\n\t\t\t\tans = ans[:0]\n\t\t\t}\n\t\t\tans = append(ans, k)\n\t\t}\n\t}\n\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/599/ac599_test.go",
    "content": "package problem599\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findRestaurant(t *testing.T) {\n\tlist1 := []string{\"Shogun\", \"Tapioca Express\", \"Burger King\", \"KFC\"}\n\tlist2 := []string{\"Piatti\", \"The Grill at Torrey Pines\", \"Hungry Hunter Steakhouse\", \"Shogun\"}\n\n\tfmt.Println(findRestaurant(list1, list2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/605/ac605.go",
    "content": "package problem605\n\nfunc canPlaceFlowers(flowerbed []int, n int) bool {\n\tcount := 0\n\tfor i := 0; i < len(flowerbed); i++ {\n\t\tif 0 == flowerbed[i] {\n\t\t\tprev, next := 0, 0\n\t\t\tif i == len(flowerbed)-1 {\n\t\t\t\tnext = 0\n\t\t\t} else {\n\t\t\t\tnext = flowerbed[i+1]\n\t\t\t}\n\n\t\t\tif 0 == i {\n\t\t\t\tprev = 0\n\t\t\t} else {\n\t\t\t\tprev = flowerbed[i-1]\n\t\t\t}\n\n\t\t\tif 0 == prev && next == 0 {\n\t\t\t\tflowerbed[i] = 1\n\t\t\t\tcount++\n\t\t\t}\n\t\t}\n\t}\n\t// 花圃能够继续种植的花卉数目大于给的花卉数目，则成立\n\treturn count >= n\n}\n"
  },
  {
    "path": "algorithm/leetcode/605/ac605_test.go",
    "content": "package problem605\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_canPlaceFlowers(t *testing.T) {\n\tflowerbed := []int{1, 0, 0, 0, 1}\n\n\tfmt.Println(canPlaceFlowers(flowerbed, 1))\n\tfmt.Println(canPlaceFlowers(flowerbed, 2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/606/ac606.go",
    "content": "package problem606\n\nimport \"strconv\"\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc tree2str(t *TreeNode) string {\n\tif nil == t {\n\t\treturn \"\"\n\t}\n\n\tans := strconv.Itoa(t.Val)\n\tstrLeft := tree2str(t.Left)\n\tstrRight := tree2str(t.Right)\n\n\tif \"\" == strLeft && \"\" == strRight {\n\t\treturn ans\n\t}\n\tif \"\" == strLeft {\n\t\treturn ans + \"()\" + \"(\" + strRight + \")\"\n\t}\n\tif \"\" == strRight {\n\t\treturn ans + \"(\" + strLeft + \")\"\n\t}\n\treturn ans + \"(\" + strLeft + \")\" + \"(\" + strRight + \")\"\n}\n"
  },
  {
    "path": "algorithm/leetcode/617/ac617.go",
    "content": "package problem617\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc mergeTrees(t1 *TreeNode, t2 *TreeNode) *TreeNode {\n\tif nil == t1 {\n\t\treturn t2\n\t}\n\tif nil == t2 {\n\t\treturn t1\n\t}\n\n\treturn &TreeNode{Val: t1.Val + t2.Val, Left: mergeTrees(t1.Left, t2.Left), Right: mergeTrees(t1.Right, t2.Right)}\n}\n"
  },
  {
    "path": "algorithm/leetcode/628/ac628.go",
    "content": "package problem628\n\nimport (\n\t\"sort\"\n\t\"math\"\n)\n\nfunc maximumProduct(nums []int) int {\n\tif len(nums) < 3 {\n\t\treturn 0\n\t}\n\n\tsort.Ints(nums)\n\tans1, ans2 := 1, 1\n\tfor i := len(nums) - 1; i >= len(nums)-3; i-- {\n\t\tans1 *= nums[i]\n\t}\n\n\tfor i := 0; i < 2; i++ {\n\t\tans2 *= nums[i]\n\t}\n\tans2 *= nums[len(nums)-1]\n\n\tif ans1 > ans2 {\n\t\treturn ans1\n\t}\n\treturn ans2\n}\n\nfunc maximumProduct2(nums []int) int {\n\tif len(nums) < 3 {\n\t\treturn 0\n\t}\n\n\tmax1, max2, max3 := math.MinInt32, math.MinInt32, math.MinInt32\n\tmin1, min2 := math.MaxInt32, math.MaxInt32\n\tfor _, v := range nums {\n\t\tif v > max1 {\n\t\t\tmax3 = max2\n\t\t\tmax2 = max1\n\t\t\tmax1 = v\n\t\t} else if v > max2 {\n\t\t\tmax3 = max2\n\t\t\tmax2 = v\n\t\t} else if v > max3 {\n\t\t\tmax3 = v\n\t\t}\n\n\t\tif v < min1 {\n\t\t\tmin2 = min1\n\t\t\tmin1 = v\n\t\t} else if v < min2 {\n\t\t\tmin2 = v\n\t\t}\n\t}\n\treturn myMax(max1*max2*max3, min1*min2*max1)\n}\n\nfunc myMax(a, b int) int {\n\tif a >= b {\n\t\treturn a\n\t}\n\treturn b\n}\n"
  },
  {
    "path": "algorithm/leetcode/633/ac633.go",
    "content": "package problem633\n\nimport \"math\"\n\nfunc judgeSquareSum(c int) bool {\n\tif c < 0 {\n\t\treturn false\n\t}\n\n\tleft, right := 0, int(math.Sqrt(float64(c)))\n\tfor left <= right {\n\t\tcurrent := left*left + right*right\n\t\tif current < c {\n\t\t\tleft++\n\t\t} else if current > c {\n\t\t\tright--\n\t\t} else {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n"
  },
  {
    "path": "algorithm/leetcode/637/ac637.go",
    "content": "package problem637\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc averageOfLevels(root *TreeNode) []float64 {\n\tif nil == root {\n\t\treturn nil\n\t}\n\n\tans := make([]float64, 0)\n\t// 模拟队列\n\tqueue := make([]*TreeNode, 0)\n\tqueue = append(queue, root)\n\tfor len(queue) != 0 {\n\t\tn := len(queue)\n\t\tsum := 0.0\n\t\tfor i := 0; i < n; i++ {\n\t\t\tnode := queue[0]\n\t\t\tsum += float64(node.Val)\n\t\t\tif nil != node.Left {\n\t\t\t\tqueue = append(queue, node.Left)\n\t\t\t}\n\t\t\tif nil != node.Right {\n\t\t\t\tqueue = append(queue, node.Right)\n\t\t\t}\n\t\t\t// 从队列中删除头部元素，相当于头部元素出队\n\t\t\tqueue = queue[1:]\n\t\t}\n\t\tans = append(ans, sum/float64(n))\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/643/ac643.go",
    "content": "package problem643\n\nimport \"math\"\n\nfunc findMaxAverage(nums []int, k int) float64 {\n\tif nil == nums || len(nums) == 0 {\n\t\treturn 0\n\t}\n\n\tmaxSum := math.MinInt32\n\tfor i := 0; i <= len(nums)-k; i++ {\n\t\ttemp := 0\n\t\tfor j := 0; j < k; j++ {\n\t\t\ttemp += nums[i+j]\n\t\t}\n\t\tif maxSum < temp {\n\t\t\tmaxSum = temp\n\t\t}\n\t}\n\treturn float64(maxSum) / float64(k)\n}\n"
  },
  {
    "path": "algorithm/leetcode/643/ac643_test.go",
    "content": "package problem643\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findMaxAverage(t *testing.T) {\n\tnums := []int{1, 12, -5, -6, 50, 3}\n\n\tfmt.Println(findMaxAverage(nums, 4))\n\n\tnums2 := []int{-1}\n\tfmt.Println(findMaxAverage(nums2, 1))\n\n}\n"
  },
  {
    "path": "algorithm/leetcode/645/ac645.go",
    "content": "package problem645\n\nfunc findErrorNums(nums []int) []int {\n\tif nil == nums || len(nums) < 2 {\n\t\treturn nil\n\t}\n\n\tans := make([]int, 0)\n\tfor _, v := range nums {\n\t\tif 0 > nums[myAbs(v)-1] {\n\t\t\t// 找到重复的数字\n\t\t\tans = append(ans, myAbs(v))\n\t\t} else {\n\t\t\tnums[myAbs(v)-1] *= -1\n\t\t}\n\t}\n\tfor i := 0; i < len(nums); i++ {\n\t\t// 找到缺失元素的位置\n\t\tif nums[i] > 0 {\n\t\t\tans = append(ans, i+1)\n\t\t}\n\t}\n\treturn ans\n}\n\nfunc myAbs(a int) int {\n\tif a < 0 {\n\t\treturn -a\n\t}\n\treturn a\n}\n"
  },
  {
    "path": "algorithm/leetcode/645/ac645_test.go",
    "content": "package problem645\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findErrorNums(t *testing.T) {\n\tnums := []int{4, 2, 1, 2}\n\tfmt.Println(findErrorNums(nums))\n}\n"
  },
  {
    "path": "algorithm/leetcode/653/ac653.go",
    "content": "package problem653\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc findTarget(root *TreeNode, k int) bool {\n\tif nil == root {\n\t\treturn false\n\t}\n\n\tdict := make(map[int]bool, 0)\n\treturn dfs(root, k, dict)\n}\n\nfunc dfs(node *TreeNode, k int, dict map[int]bool) bool {\n\tif nil == node {\n\t\treturn false\n\t}\n\tif dict[k-node.Val] {\n\t\treturn true\n\t}\n\tdict[node.Val] = true\n\treturn dfs(node.Left, k, dict) || dfs(node.Right, k, dict)\n}\n"
  },
  {
    "path": "algorithm/leetcode/653/ac653_test.go",
    "content": "package problem653\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findTarget(t *testing.T) {\n\tnode2 := TreeNode{Val: 2, Left: nil, Right: nil}\n\tnode4 := TreeNode{Val: 4, Left: nil, Right: nil}\n\tnode7 := TreeNode{Val: 7, Left: nil, Right: nil}\n\tnode3 := TreeNode{Val: 3, Left: &node2, Right: &node4}\n\tnode6 := TreeNode{Val: 2, Left: nil, Right: &node7}\n\tnode5 := TreeNode{Val: 5, Left: &node3, Right: &node6}\n\n\tfmt.Println(findTarget(&node5, 9))\n}\n"
  },
  {
    "path": "algorithm/leetcode/657/ac657.go",
    "content": "package problem657\n\nimport \"strings\"\n\ntype Position struct {\n\tx, y int\n}\n\nfunc judgeCircle(moves string) bool {\n\tpst := Position{x: 0, y: 0}\n\n\tfor _, v := range moves {\n\t\tif 'R' == v {\n\t\t\tpst.x++\n\t\t} else if 'L' == v {\n\t\t\tpst.x--\n\t\t} else if 'U' == v {\n\t\t\tpst.y++\n\t\t} else if 'D' == v {\n\t\t\tpst.y--\n\t\t} else {\n\t\t\tcontinue\n\t\t}\n\t}\n\n\tif 0 == pst.x && pst.x == pst.y {\n\t\treturn true\n\t}\n\treturn false\n}\n\nfunc judgeCircle2(moves string) bool {\n\tr := strings.Count(moves, \"R\")\n\tl := strings.Count(moves, \"L\")\n\tu := strings.Count(moves, \"U\")\n\td := strings.Count(moves, \"D\")\n\n\tif l == r && u == d {\n\t\treturn true\n\t}\n\treturn false\n}\n"
  },
  {
    "path": "algorithm/leetcode/657/ac657_test.go",
    "content": "package problem657\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_judgeCircle(t *testing.T) {\n\tfmt.Println(judgeCircle(\"UD\"))\n\tfmt.Println(judgeCircle(\"LL\"))\n\tfmt.Println(judgeCircle2(\"UD\"))\n\tfmt.Println(judgeCircle2(\"LL\"))\n}\n"
  },
  {
    "path": "algorithm/leetcode/661/ac661.go",
    "content": "package problem661\n\nfunc imageSmoother(M [][]int) [][]int {\n\tif nil == M || len(M) <= 0 || len(M[0]) <= 0 {\n\t\treturn nil\n\t}\n\n\t// 行数、列数\n\tnx, ny := len(M), len(M[0])\n\tans := make([][]int, nx)\n\tfor i := 0; i < nx; i++ {\n\t\tans[i] = make([]int, ny)\n\t\tfor j := 0; j < ny; j++ {\n\t\t\tans[i][j] = smooth(M, i, j)\n\t\t}\n\t}\n\treturn ans\n}\n\nfunc smooth(M [][]int, x, y int) int {\n\tnx, ny := len(M), len(M[0])\n\tsum, count := 0, 0\n\n\t// i: -1 -> 上一行, 0 -> 本行， 1 -> 下一行\n\t// j: -1 -> 左侧列, 0 -> 本列， 1 -> 右侧列\n\tfor i := -1; i <= 1; i++ {\n\t\tfor j := -1; j <= 1; j++ {\n\t\t\tif x+i < 0 || x+i >= nx || y+j < 0 || y+j >= ny {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tcount++\n\t\t\tsum += M[x+i][y+j]\n\t\t}\n\t}\n\treturn sum / count\n}\n"
  },
  {
    "path": "algorithm/leetcode/661/ac661_test.go",
    "content": "package problem661\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_imageSmoother(t *testing.T) {\n\tM := [][]int{\n\t\t{0, 1, 2, 3},\n\t\t{2, 3, 1, 1},\n\t}\n\n\tfmt.Println(imageSmoother(M))\n}\n"
  },
  {
    "path": "algorithm/leetcode/665/ac665.go",
    "content": "package problem665\n\nfunc checkPossibility(nums []int) bool {\n\tif nil == nums || len(nums) <= 0 {\n\t\treturn false\n\t}\n\tif len(nums) == 1 {\n\t\treturn true\n\t}\n\n\tcount := 0\n\tfor i := 1; i < len(nums) && count <= 1; i++ {\n\t\tif nums[i-1] > nums[i] {\n\t\t\tcount++\n\t\t\tif i-2 < 0 || nums[i-2] <= nums[i] {\n\t\t\t\tnums[i-1] = nums[i]\n\t\t\t} else {\n\t\t\t\tnums[i] = nums[i-1]\n\t\t\t}\n\t\t}\n\t}\n\n\treturn count <= 1\n}\n"
  },
  {
    "path": "algorithm/leetcode/665/ac665_test.go",
    "content": "package problem665\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_checkPossibility(t *testing.T) {\n\tnums := []int{4, 2, 1}\n\tfmt.Println(checkPossibility(nums))\n\n\tnums2 := []int{4, 2, 3}\n\tfmt.Println(checkPossibility(nums2))\n\n\tnums3 := []int{3, 4, 2, 3}\n\tfmt.Println(checkPossibility(nums3))\n}\n"
  },
  {
    "path": "algorithm/leetcode/669/ac669.go",
    "content": "package problem669\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc trimBST(root *TreeNode, L int, R int) *TreeNode {\n\tif nil == root {\n\t\treturn nil\n\t}\n\n\tif root.Val < L {\n\t\treturn trimBST(root.Right, L, R)\n\t}\n\tif root.Val > R {\n\t\treturn trimBST(root.Left, L, R)\n\t}\n\troot.Left = trimBST(root.Left, L, R)\n\troot.Right = trimBST(root.Right, L, R)\n\treturn root\n}\n"
  },
  {
    "path": "algorithm/leetcode/671/ac671.go",
    "content": "package problem671\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc findSecondMinimumValue(root *TreeNode) int {\n\tif nil == root {\n\t\treturn -1\n\t}\n\n\treturn findCore(root, root.Val)\n}\n\nfunc findCore(node *TreeNode, min int) int {\n\tif nil == node {\n\t\treturn -1\n\t}\n\tif node.Val > min {\n\t\treturn node.Val\n\t}\n\n\tleftMin := findCore(node.Left, min)\n\trightMin := findCore(node.Right, min)\n\tif -1 == leftMin || -1 == rightMin {\n\t\treturn myMax(leftMin, rightMin)\n\t} else {\n\t\treturn myMin(leftMin, rightMin)\n\t}\n}\n\nfunc myMin(a, b int) int {\n\tif a <= b {\n\t\treturn a\n\t}\n\treturn b\n}\n\nfunc myMax(a, b int) int {\n\tif a >= b {\n\t\treturn a\n\t}\n\treturn b\n}\n"
  },
  {
    "path": "algorithm/leetcode/671/ac671_test.go",
    "content": "package problem671\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findSecondMinimumValue(t *testing.T) {\n\tnode35 := TreeNode{Val: 5}\n\tnode37 := TreeNode{Val: 7}\n\tnode22 := TreeNode{Val: 2}\n\tnode25 := TreeNode{Val: 5, Left: &node35, Right: &node37}\n\tnode12 := TreeNode{Val: 2, Left: &node22, Right: &node25}\n\n\tfmt.Println(findSecondMinimumValue(&node12))\n}\n"
  },
  {
    "path": "algorithm/leetcode/674/ac674.go",
    "content": "package problem674\n\nfunc findLengthOfLCIS(nums []int) int {\n\tif nil == nums {\n\t\treturn 0\n\t}\n\n\tans, cnt := 0, 0\n\tfor i := 0; i < len(nums); i++ {\n\t\tif 0 == i || nums[i-1] < nums[i] {\n\t\t\tcnt++\n\t\t\tif cnt > ans {\n\t\t\t\tans = cnt\n\t\t\t}\n\t\t} else {\n\t\t\tcnt = 1\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/674/ac674_test.go",
    "content": "package problem674\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findLengthOfLCIS(t *testing.T) {\n\tnums := []int{1, 3, 5, 4, 7}\n\tfmt.Println(findLengthOfLCIS(nums))\n}\n"
  },
  {
    "path": "algorithm/leetcode/680/ac680.go",
    "content": "package problem680\n\nfunc validPalindrome(s string) bool {\n\tfor l, r := 0, len(s)-1; l < r; {\n\t\tif s[l] != s[r] {\n\t\t\treturn isPalindromic(s, l+1, r) || isPalindromic(s, l, r-1)\n\t\t} else {\n\t\t\tl++\n\t\t\tr--\n\t\t}\n\t}\n\treturn true\n}\n\nfunc isPalindromic(s string, l, r int) bool {\n\tfor l < r {\n\t\tif s[l] != s[r] {\n\t\t\treturn false\n\t\t} else {\n\t\t\tl++\n\t\t\tr--\n\t\t}\n\t}\n\treturn true\n}\n"
  },
  {
    "path": "algorithm/leetcode/682/ac682.go",
    "content": "package problem682\n\nimport \"strconv\"\n\nfunc calPoints(ops []string) int {\n\tif nil == ops {\n\t\treturn 0\n\t}\n\n\tsum := 0\n\tstack := make([]int, 0)\n\tfor _, op := range ops {\n\t\tswitch op {\n\t\tcase \"C\":\n\t\t\tsum -= stack[len(stack)-1]\n\t\t\tstack = stack[:len(stack)-1]\n\t\tcase \"D\":\n\t\t\tval := stack[len(stack)-1] * 2\n\t\t\tsum += val\n\t\t\tstack = append(stack, val)\n\t\tcase \"+\":\n\t\t\tval := stack[len(stack)-1] + stack[len(stack)-2]\n\t\t\tsum += val\n\t\t\tstack = append(stack, val)\n\t\tdefault:\n\t\t\tval, _ := strconv.Atoi(op)\n\t\t\tstack = append(stack, val)\n\t\t\tsum += val\n\t\t}\n\t}\n\treturn sum\n}\n"
  },
  {
    "path": "algorithm/leetcode/682/ac682_test.go",
    "content": "package problem682\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_calPoints(t *testing.T) {\n\tops := []string{\"5\", \"-2\", \"4\", \"C\", \"D\", \"9\", \"+\", \"+\"}\n\tfmt.Println(calPoints(ops))\n}\n"
  },
  {
    "path": "algorithm/leetcode/686/ac686.go",
    "content": "package problem686\n\nimport \"strings\"\n\nfunc repeatedStringMatch(A string, B string) int {\n\tif strings.Contains(A, B) {\n\t\treturn 1\n\t}\n\n\ttempA := A\n\tfor i := 0; len(tempA) <= 10000; i++ {\n\t\ttempA += A\n\t\tif strings.Contains(tempA, B) {\n\t\t\treturn i + 2\n\t\t}\n\t}\n\treturn -1\n}\n\nfunc repeatedStringMatch2(A string, B string) int {\n\tcount := 0\n\n\tvar strb string\n\tfor len(strb) < len(B) {\n\t\tstrb += A\n\t\tcount++\n\t}\n\n\tif strings.Contains(strb, B) {\n\t\treturn count\n\t}\n\tif strb += A; strings.Contains(strb, B) {\n\t\tcount++\n\t\treturn count\n\t}\n\treturn -1\n}\n"
  },
  {
    "path": "algorithm/leetcode/686/ac686_test.go",
    "content": "package problem686\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_repeatedStringMatch(t *testing.T) {\n\ta := \"abababaaba\"\n\tb := \"aabaaba\"\n\n\tfmt.Println(repeatedStringMatch(a, b))\n\n\taa := \"bb\"\n\tbb := \"bbbbbbb\"\n\tfmt.Println(repeatedStringMatch(aa, bb))\n\n\tfmt.Println(repeatedStringMatch2(a, b))\n\tfmt.Println(repeatedStringMatch2(aa, bb))\n}\n"
  },
  {
    "path": "algorithm/leetcode/687/ac687.go",
    "content": "package problem687\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\nfunc longestUnivaluePath(root *TreeNode) int {\n\tans := make([]int, 1)\n\tif nil != root {\n\t\tdfs(root, ans)\n\t}\n\treturn ans[0]\n}\n\nfunc dfs(node *TreeNode, res []int) int {\n\tl := 0\n\tif nil != node.Left {\n\t\tl = dfs(node.Left, res)\n\t}\n\tr := 0\n\tif nil != node.Right {\n\t\tr = dfs(node.Right, res)\n\t}\n\n\tresl := 0\n\tif nil != node.Left && node.Left.Val == node.Val {\n\t\tresl = l + 1\n\t}\n\tresr := 0\n\tif nil != node.Right && node.Right.Val == node.Val {\n\t\tresr = r + 1\n\t}\n\n\t// 当前节点的左右子树连接，成为最长同值路径\n\tif res[0] < resl+resr {\n\t\tres[0] = resl + resr\n\t}\n\n\t// 最长同值路径仅出现在当前节点的左子树 或者 右子树\n\tif resl >= resr {\n\t\treturn resl\n\t} else {\n\t\treturn resr\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/693/ac693.go",
    "content": "package problem693\n\nimport (\n\t\"strings\"\n\t\"fmt\"\n)\n\nfunc hasAlternatingBits(n int) bool {\n\tres := decimalToBinary(n)\n\tfor i, temp := 1, res[0]; i < len(res); i++ {\n\t\tif temp == res[i] {\n\t\t\treturn false\n\t\t} else {\n\t\t\ttemp = res[i]\n\t\t}\n\t}\n\treturn true\n}\n\nfunc decimalToBinary(n int) []int {\n\tif 0 == n {\n\t\treturn []int{0}\n\t}\n\n\tans := make([]int, 0)\n\tfor 0 != n {\n\t\tans = append(ans, n%2)\n\t\tn /= 2\n\t}\n\treturn ans\n}\n\nfunc hasAlternatingBits2(n int) bool {\n\tstrN := fmt.Sprintf(\"%b\", n)\n\treturn !(strings.Contains(strN, \"00\") || strings.Contains(strN, \"11\"))\n}\n"
  },
  {
    "path": "algorithm/leetcode/693/ac693_test.go",
    "content": "package problem693\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_hasAlternatingBits2(t *testing.T) {\n\tfmt.Println(hasAlternatingBits2(5))\n\tfmt.Println(hasAlternatingBits2(7))\n}\n"
  },
  {
    "path": "algorithm/leetcode/695/ac695.go",
    "content": "package problem695\n\nfunc maxAreaOfIsland(grid [][]int) int {\n\tmaxArea := 0\n\tfor i := 0; i < len(grid); i++ {\n\t\tfor j := 0; j < len(grid[0]); j++ {\n\t\t\tif 1 == grid[i][j] {\n\t\t\t\tcurrent := AreaOfIsland(grid, i, j)\n\t\t\t\tif maxArea < current {\n\t\t\t\t\tmaxArea = current\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn maxArea\n}\n\nfunc AreaOfIsland(grid [][]int, i, j int) int {\n\tif 0 <= i && i < len(grid) && 0 <= j && j < len(grid[0]) && 1 == grid[i][j] {\n\t\t// 当前元素置为 0 ，避免重复计算\n\t\tgrid[i][j] = 0\n\t\treturn 1 + AreaOfIsland(grid, i-1, j) + AreaOfIsland(grid, i+1, j) + AreaOfIsland(grid, i, j-1) + AreaOfIsland(grid, i, j+1)\n\t}\n\treturn 0\n}\n"
  },
  {
    "path": "algorithm/leetcode/696/ac696.go",
    "content": "package problem696\n\n//preRun count the same item happend before (let say you have 0011, preRun = 2 when you hit the first 1, means there are two zeros before first '1')\n//curRun count the current number of items (let say you have 0011, curRun = 2 when you hit the second 1, means there are two 1s so far)\n//Whenever item change (from 0 to 1 or from 1 to 0), preRun change to curRun, reset curRun to 1 (store the curRun number into PreRun, reset curRun)\n//Every time preRun >= curRun means there are more 0s before 1s, so could do count++ .\n// (This was the tricky one, ex. 0011 when you hit the first '1', curRun = 1, preRun = 2, means 0s number is larger than 1s number,\n// so we could form \"01\" at this time, count++ . When you hit the second '1', curRun = 2, preRun = 2, means 0s' number equals to 1s' number,\n// so we could form \"0011\" at this time, that is why count++)\nfunc countBinarySubstrings(s string) int {\n\tprevRun, curRun, ans := 0, 1, 0\n\tfor i := 1; i < len(s); i++ {\n\t\tif s[i] == s[i-1] {\n\t\t\tcurRun++\n\t\t} else {\n\t\t\tprevRun = curRun\n\t\t\tcurRun = 1\n\t\t}\n\t\tif prevRun >= curRun {\n\t\t\tans++\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/697/ac697.go",
    "content": "package problem697\n\nfunc findShortestSubArray(nums []int) int {\n\tsize := len(nums)\n\tif 2 > size {\n\t\treturn size\n\t}\n\n\tfirst := make(map[int]int, size)\n\tcount := make(map[int]int, size)\n\tmaxCount := 1\n\tminLen := size\n\tfor i, v := range nums {\n\t\tcount[v]++\n\t\tif 1 == count[v] {\n\t\t\tfirst[v] = i\n\t\t} else {\n\t\t\tl := i - first[v] + 1\n\t\t\tif maxCount < count[v] || (maxCount == count[v] && l < minLen) {\n\t\t\t\tmaxCount = count[v]\n\t\t\t\tminLen = l\n\t\t\t}\n\t\t}\n\t}\n\n\tif len(count) == size {\n\t\treturn 1\n\t}\n\treturn minLen\n}\n"
  },
  {
    "path": "algorithm/leetcode/717/ac717.go",
    "content": "package problem717\n\n//if there is only one symbol in array the answer is always true (as last element is 0)\n//if there are two 0s at the end again the answer is true no matter what the rest symbols are( ...1100, ...1000,)\n//if there is 1 right before the last element(...10), the outcome depends on the count of sequential 1, i.e.\n//a) if there is odd amount of 1(10, ...01110, etc) the answer is false as there is a single 1 without pair\n//b) if it's even (110, ...011110, etc) the answer is true, as 0 at the end doesn't have anything to pair with\nfunc isOneBitCharacter(bits []int) bool {\n\tones := 0\n\tfor i := len(bits) - 2; i >= 0 && 1 == bits[i]; i-- {\n\t\tones++\n\t}\n\n\tif ones%2 != 0 {\n\t\treturn false\n\t}\n\treturn true\n}\n"
  },
  {
    "path": "algorithm/leetcode/724/ac724.go",
    "content": "package problem724\n\nfunc pivotIndex(nums []int) int {\n\tif nil == nums || len(nums) == 0 {\n\t\treturn -1\n\t}\n\n\tpreSum := make([]int, len(nums))\n\tpreSum[0] = nums[0]\n\tfor i := 1; i < len(nums); i++ {\n\t\tpreSum[i] = preSum[i-1] + nums[i]\n\t}\n\n\tfor i := 0; i < len(nums); i++ {\n\t\t// 左边和 == 右边和，则返回当前的下标\n\t\tif preSum[i]-nums[i] == preSum[len(nums)-1]-preSum[i] {\n\t\t\treturn i\n\t\t}\n\t}\n\treturn -1\n}\n"
  },
  {
    "path": "algorithm/leetcode/728/ac728.go",
    "content": "package problem728\n\nfunc selfDividingNumbers(left int, right int) []int {\n\tans := make([]int, 0)\n\tfor i := left; i <= right; i++ {\n\t\tvalue := i\n\t\tfor ; value > 0; value /= 10 {\n\t\t\tif 0 == value%10 || 0 != (i%(value%10)) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif 0 == value {\n\t\t\tans = append(ans, i)\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/744/ac744.go",
    "content": "package problem744\n\nfunc nextGreatestLetter(letters []byte, target byte) byte {\n\tidx := 0\n\tfor i := 0; i < len(letters); i++ {\n\t\tif letters[i] > target {\n\t\t\tidx = i\n\t\t\tbreak\n\t\t}\n\t}\n\treturn letters[idx]\n}\n"
  },
  {
    "path": "algorithm/leetcode/746/ac746.go",
    "content": "package problem746\n\nfunc minCostClimbingStairs(cost []int) int {\n\tfor i := len(cost) - 3; i >= 0; i-- {\n\t\tcost[i] += myMin(cost[i+1], cost[i+2])\n\t}\n\treturn myMin(cost[0], cost[1])\n}\n\nfunc myMin(a, b int) int {\n\tif a <= b {\n\t\treturn a\n\t}\n\treturn b\n}\n"
  },
  {
    "path": "algorithm/leetcode/747/ac747.go",
    "content": "package problem747\n\nfunc dominantIndex(nums []int) int {\n\tif len(nums) < 1 {\n\t\treturn -1\n\t}\n\tif len(nums) == 1 {\n\t\treturn 0\n\t}\n\n\tid1, id2 := -1, -1\n\tfor i := 0; i < len(nums); i++ {\n\t\tif -1 == id1 || nums[i] > nums[id1] {\n\t\t\tid2 = id1\n\t\t\tid1 = i\n\t\t} else if -1 == id2 || nums[i] > nums[id2] {\n\t\t\tid2 = i\n\t\t}\n\t}\n\n\tif nums[id2]*2 <= nums[id1] {\n\t\treturn id1\n\t}\n\treturn -1\n}\n"
  },
  {
    "path": "algorithm/leetcode/747/ac747_test.go",
    "content": "package problem747\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_dominantIndex(t *testing.T) {\n\tnums := []int{0, 0, 1, 2}\n\tfmt.Println(dominantIndex(nums))\n}\n"
  },
  {
    "path": "algorithm/leetcode/762/ac762.go",
    "content": "package problem762\n\nfunc countPrimeSetBits(L, R int) int {\n\tprimes := make(map[int]bool, 0)\n\tprimes[2] = true\n\tprimes[3] = true\n\tprimes[5] = true\n\tprimes[7] = true\n\tprimes[11] = true\n\tprimes[13] = true\n\tprimes[17] = true\n\tprimes[19] = true\n\n\tcnt := 0\n\tfor i := L; i <= R; i++ {\n\t\tbits := 0\n\t\tfor n := i; n > 0; n /= 2 {\n\t\t\tbits += n & 1\n\t\t}\n\t\tif primes[bits] {\n\t\t\tcnt++\n\t\t}\n\t}\n\treturn cnt\n}\n"
  },
  {
    "path": "algorithm/leetcode/766/ac766.go",
    "content": "package problem766\n\n// 无需考虑复杂，直接判断是否符合要求即可\nfunc isToeplitzMatrix(matrix [][]int) bool {\n\tfor i := 0; i < len(matrix)-1; i++ {\n\t\tfor j := 0; j < len(matrix[0])-1; j++ {\n\t\t\tif matrix[i][j] != matrix[i+1][j+1] {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t}\n\treturn true\n}\n"
  },
  {
    "path": "algorithm/leetcode/766/ac766_test.go",
    "content": "package problem766\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_isToeplitzMatrix(t *testing.T) {\n\tdata := [][]int{{1, 2, 3, 4}, {5, 1, 2, 3}, {9, 5, 1, 2}}\n\tfmt.Println(isToeplitzMatrix(data))\n}\n"
  },
  {
    "path": "algorithm/leetcode/771/ac771.go",
    "content": "package problem771\n\nfunc numJewelsInStones(J string, S string) int {\n\tans := 0\n\tdict := make(map[uint8]bool, len(J))\n\tfor i := 0; i < len(J); i++ {\n\t\tdict[J[i]] = true\n\t}\n\tfor i := 0; i < len(S); i++ {\n\t\tif dict[S[i]] {\n\t\t\tans++\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/771/ac771_test.go",
    "content": "package problem771\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_numJewelsInStones(t *testing.T) {\n\tj1 := \"aA\"\n\ts1 := \"aAAbbbb\"\n\tfmt.Println(numJewelsInStones(j1, s1))\n\n\tj2 := \"z\"\n\ts2 := \"ZZ\"\n\tfmt.Println(numJewelsInStones(j2, s2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/783/ac783.go",
    "content": "package problem783\n\nimport \"math\"\n\ntype TreeNode struct {\n\tVal   int\n\tLeft  *TreeNode\n\tRight *TreeNode\n}\n\n// 因为给定的是二叉搜索树，故可以采用中序遍历 data[1]代表pre\nfunc minDiffInBST(root *TreeNode) int {\n\tdata := make([]int, 2)\n\tdata[0] = math.MaxInt32\n\tdata[1] = -1\n\tcheck(root, data)\n\treturn data[0]\n}\n\nfunc check(node *TreeNode, nums []int) {\n\tif nil == node {\n\t\treturn\n\t}\n\tcheck(node.Left, nums)\n\tif -1 != nums[1] {\n\t\tnums[0] = myMin(nums[0], node.Val-nums[1])\n\t}\n\tnums[1] = node.Val\n\tcheck(node.Right, nums)\n}\n\nfunc myMin(a, b int) int {\n\tif a <= b {\n\t\treturn a\n\t}\n\treturn b\n}\n"
  },
  {
    "path": "algorithm/leetcode/783/ac783_test.go",
    "content": "package problem783\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_minDiffInBST(t *testing.T) {\n\tnode44 := TreeNode{Val: 44}\n\tnode50 := TreeNode{Val: 50, Left: &node44}\n\tnode58 := TreeNode{Val: 58, Left: &node50}\n\tnode34 := TreeNode{Val: 34, Right: &node58}\n\tnode27 := TreeNode{Val: 27, Right: &node34}\n\n\tfmt.Println(minDiffInBST(&node27))\n}\n"
  },
  {
    "path": "algorithm/leetcode/784/ac784.go",
    "content": "package problem784\n\n// 递归解法\n// 每当遇到一个字符时，分别统计 1.该字符为小写时的所有情况 2.该字符为大写时的所有情况\nfunc letterCasePermutation(S string) []string {\n\tans := make([]string, 0)\n\tif len(S) < 1 {\n\t\treturn []string{\"\"}\n\t}\n\treturn core(ans, []byte(S), 0)\n}\n\nfunc core(ans []string, chars []byte, index int) []string {\n\tif index == len(chars) {\n\t\tans = append(ans, string(chars))\n\t} else {\n\t\tif isLetter(chars[index]) {\n\t\t\tchars[index] = toLower(chars[index])\n\t\t\tans = core(ans, chars, index+1)\n\t\t\tchars[index] = toUpper(chars[index])\n\t\t}\n\t\tans = core(ans, chars, index+1)\n\t}\n\treturn ans\n}\n\nfunc isLetter(c byte) bool {\n\tif (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') {\n\t\treturn true\n\t}\n\treturn false\n}\n\nfunc toLower(c byte) byte {\n\tif c >= 'A' && c <= 'Z' {\n\t\tdis := byte('a' - 'A')\n\t\treturn c + dis\n\t}\n\treturn c\n}\n\nfunc toUpper(c byte) byte {\n\tif c >= 'a' && c <= 'z' {\n\t\tdis := byte('a' - 'A')\n\t\treturn c - dis\n\t}\n\treturn c\n}\n"
  },
  {
    "path": "algorithm/leetcode/784/ac784_test.go",
    "content": "package problem784\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_letterCasePermutation(t *testing.T) {\n\ts := \"a1b2\"\n\tfmt.Println(letterCasePermutation(s))\n\n\ts1 := \"\"\n\tfmt.Println(letterCasePermutation(s1))\n}\n"
  },
  {
    "path": "algorithm/leetcode/788/ac788.go",
    "content": "package problem788\n\nfunc rotatedDigits(N int) int {\n\tcount := 0\n\tfor i := 1; i <= N; i++ {\n\t\tif isValid(i) {\n\t\t\tcount++\n\t\t}\n\t}\n\treturn count\n}\n\nfunc isValid(n int) bool {\n\tans := false\n\tfor 0 < n {\n\t\tif 2 == n%10 {\n\t\t\tans = true\n\t\t}\n\t\tif 5 == n%10 {\n\t\t\tans = true\n\t\t}\n\t\tif 6 == n%10 {\n\t\t\tans = true\n\t\t}\n\t\tif 9 == n%10 {\n\t\t\tans = true\n\t\t}\n\t\tif 3 == n%10 {\n\t\t\treturn false\n\t\t}\n\t\tif 4 == n%10 {\n\t\t\treturn false\n\t\t}\n\t\tif 7 == n%10 {\n\t\t\treturn false\n\t\t}\n\t\tn /= 10\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/796/ac796.go",
    "content": "package problem706\n\nimport \"strings\"\n\n// 拼接2个字符串，正好满足了循环条件\nfunc rotateString(A string, B string) bool {\n\tif len(A) != len(B){\n\t\treturn false\n\t}\n\treturn strings.Contains(A+A, B)\n}\n"
  },
  {
    "path": "algorithm/leetcode/804/ac804.go",
    "content": "package problem804\n\nfunc uniqueMorseRepresentations(words []string) int {\n\td := []string{\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\", \"....\", \"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\", \"---\", \".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\", \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"}\n\n\tans := make(map[string]int, 0)\n\tfor _, word := range words {\n\t\tecd := \"\"\n\t\tfor i := 0; i < len(word); i++ {\n\t\t\tecd += d[word[i]-'a']\n\t\t}\n\t\tans[ecd]++\n\t}\n\treturn len(ans)\n}\n"
  },
  {
    "path": "algorithm/leetcode/804/ac804_test.go",
    "content": "package problem804\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_uniqueMorseRepresentations(t *testing.T) {\n\tstrList := []string{\"abc\", \"bcd\"}\n\tfmt.Println(uniqueMorseRepresentations(strList))\n}\n"
  },
  {
    "path": "algorithm/leetcode/811/ac811.go",
    "content": "package problem811\n\nimport (\n\t\"strings\"\n\t\"strconv\"\n)\n\nfunc subdomainVisits(cpdomains []string) []string {\n\tans := make(map[string]int, 0)\n\n\tfor _, item := range cpdomains {\n\t\tparts := strings.Split(item, \" \")\n\t\tdomain := parts[1]\n\t\tcount, _ := strconv.Atoi(parts[0])\n\n\t\tans[domain] += count\n\t\tidx := strings.LastIndex(domain, \".\")\n\t\tfor i := 0; i <= idx; i++ {\n\t\t\tif domain[i] == '.' {\n\t\t\t\ttemp := domain[i+1:]\n\t\t\t\tans[temp] += count\n\t\t\t}\n\t\t}\n\t}\n\n\tansList := make([]string, 0)\n\tfor k, v := range ans {\n\t\tansList = append(ansList, strconv.Itoa(v)+\" \"+k)\n\t}\n\treturn ansList\n}\n"
  },
  {
    "path": "algorithm/leetcode/811/ac811_test.go",
    "content": "package problem811\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_subdomainVisits(t *testing.T) {\n\ttest1 := []string{\"9001 discuss.leetcode.com\"}\n\tfmt.Println(subdomainVisits(test1))\n\n\ttest2 := []string{\"900 google.mail.com\", \"50 yahoo.com\", \"1 intel.mail.com\", \"5 wiki.org\"}\n\tfmt.Println(subdomainVisits(test2))\n}\n"
  },
  {
    "path": "algorithm/leetcode/812/ac812.go",
    "content": "package problem812\n\nimport \"math\"\n\n// 从坐标计算三角形的面积公式为：\n// area = |xa*yb + xb*yc + xc*ya - xa*yc - xb*ya - xc*yb| / 2\nfunc largestTriangleArea(points [][]int) float64 {\n\tans := 0.0\n\tfor _, i := range points {\n\t\tfor _, j := range points {\n\t\t\tfor _, k := range points {\n\t\t\t\tans = math.Max(ans, 0.5*math.Abs(float64(i[0]*j[1]+j[0]*k[1]+k[0]*i[1]-i[0]*k[1]-j[0]*i[1]-k[0]*j[1])))\n\t\t\t}\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/812/ac812_test.go",
    "content": "package problem812\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_largestTriangleArea(t *testing.T) {\n\tnums := [][]int{{0, 0}, {0, 1}, {1, 0}, {0, 2}, {2, 0}}\n\n\tfmt.Println(largestTriangleArea(nums))\n}\n"
  },
  {
    "path": "algorithm/leetcode/819/ac819.go",
    "content": "package problem819\n\nimport (\n\t\"strings\"\n\t\"regexp\"\n)\n\nfunc mostCommonWord(paragraph string, banned []string) string {\n\ttext := strings.ToLower(paragraph)\n\n\treg := regexp.MustCompile(\"[a-z]+\")\n\tresult := reg.FindAllString(text, -1)\n\n\tans := make(map[string]int, 0)\n\n\tfor _, word := range result {\n\t\tif !isContain(banned, word) {\n\t\t\tans[word]++\n\t\t}\n\t}\n\n\tmaxTime := 0\n\tvar ansString string\n\tfor k, v := range ans {\n\t\tif v > maxTime {\n\t\t\tmaxTime = v\n\t\t\tansString = k\n\t\t}\n\t}\n\treturn ansString\n}\n\nfunc isContain(words []string, word string) bool {\n\tfor _, w := range words {\n\t\tif w == word {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n"
  },
  {
    "path": "algorithm/leetcode/819/ac819_test.go",
    "content": "package problem819\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_mostCommonWord(t *testing.T) {\n\tpara := \"Bob hit a ball, the hit BALL flew far after it was hit.\"\n\tbanned := []string{\"hit\"}\n\n\tfmt.Println(mostCommonWord(para, banned))\n}\n"
  },
  {
    "path": "algorithm/leetcode/821/ac821.go",
    "content": "package problem821\n\nimport \"math\"\n\nfunc shortestToChar(S string, C byte) []int {\n\t// 先获得 C 的各个坐标\n\tcId := make([]int, 0)\n\tfor i := 0; i < len(S); i++ {\n\t\tif S[i] == C {\n\t\t\tcId = append(cId, i)\n\t\t}\n\t}\n\n\tans := make([]int, 0)\n\tfor i := 0; i < len(S); i++ {\n\t\tif S[i] == C {\n\t\t\tans = append(ans, 0)\n\t\t} else {\n\t\t\tminDistance := getMinDistance(cId, i)\n\t\t\tans = append(ans, minDistance)\n\t\t}\n\t}\n\treturn ans\n}\n\nfunc getMinDistance(position []int, p int) int {\n\td := math.MaxInt32\n\tfor _, item := range position {\n\t\ttemp := myAbs(p - item)\n\t\tif temp < d {\n\t\t\td = temp\n\t\t}\n\t}\n\treturn d\n}\n\nfunc myAbs(a int) int {\n\tif a < 0 {\n\t\treturn -a\n\t}\n\treturn a\n}\n"
  },
  {
    "path": "algorithm/leetcode/821/ac821_test.go",
    "content": "package problem821\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_shortestToChar(t *testing.T) {\n\tS := \"loveleetcode\"\n\tC := byte('e')\n\n\tfmt.Println(shortestToChar(S, C))\n}\n"
  },
  {
    "path": "algorithm/leetcode/824/ac824.go",
    "content": "package problem824\n\nimport (\n\t\"strings\"\n\t\"bytes\"\n)\n\nfunc toGoatLatin(S string) string {\n\twords := strings.Fields(S)\n\tvar buffer bytes.Buffer\n\n\tvowels := map[string]int{\n\t\t\"a\": 1,\n\t\t\"e\": 1,\n\t\t\"i\": 1,\n\t\t\"o\": 1,\n\t\t\"u\": 1,\n\t\t\"A\": 1,\n\t\t\"E\": 1,\n\t\t\"I\": 1,\n\t\t\"O\": 1,\n\t\t\"U\": 1,\n\t}\n\n\tfor i := 0; i < len(words); i++ {\n\t\tfirst := string(words[i][0])\n\t\tif vowels[first] == 1 {\n\t\t\tbuffer.WriteString(words[i])\n\t\t\tbuffer.WriteString(\"ma\")\n\t\t} else {\n\t\t\tbuffer.WriteString(string(words[i][1:]))\n\t\t\tbuffer.WriteString(first)\n\t\t\tbuffer.WriteString(\"ma\")\n\t\t}\n\t\tfor j := 0; j <= i; j++ {\n\t\t\tbuffer.WriteString(\"a\")\n\t\t}\n\t\tif i != len(words)-1 {\n\t\t\tbuffer.WriteString(\" \")\n\t\t}\n\n\t}\n\treturn buffer.String()\n}\n"
  },
  {
    "path": "algorithm/leetcode/824/ac824_test.go",
    "content": "package problem824\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_toGoatLatin(t *testing.T) {\n\tS := \"I speak Goat Latin\"\n\n\tfmt.Println(toGoatLatin(S))\n}\n"
  },
  {
    "path": "algorithm/leetcode/829/ac829.go",
    "content": "package problem829\n\n// 任何一个连续的序列可以写作-> (base+1,base+2,...,base+m)\n// 对于本题，我们需要检查 (1+2+...+m)+ m*base==N 是否成立\n// 即检查 sum=(1+2+...+m)   N-sum % m == 0\nfunc consecutiveNumbersSum(N int) int {\n\tcount := 0\n\tsum := 1\n\tm := 1\n\n\tfor sum <= N {\n\t\tif 0 == (N-sum)%m {\n\t\t\tcount++\n\t\t}\n\t\tm++\n\t\tsum = (1 + m) * m / 2\n\t}\n\treturn count\n}\n"
  },
  {
    "path": "algorithm/leetcode/829/ac829_test.go",
    "content": "package problem829\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_consecutiveNumbersSum(t *testing.T) {\n\tfmt.Println(consecutiveNumbersSum(1))\n\tfmt.Println(consecutiveNumbersSum(9))\n\tfmt.Println(consecutiveNumbersSum(15))\n}\n"
  },
  {
    "path": "algorithm/leetcode/830/ac830.go",
    "content": "package problem830\n\nfunc largeGroupPositions(S string) [][]int {\n\tif len(S) < 3 {\n\t\treturn [][]int{}\n\t}\n\n\tans := make([][]int, 0)\n\tstart, count := 0, 0\n\tfor i := 0; i < len(S); i++ {\n\t\tif S[i] == S[start] {\n\t\t\tcount++\n\t\t} else {\n\t\t\tif 3 <= count {\n\t\t\t\tans = append(ans, []int{start, i - 1})\n\t\t\t}\n\t\t\tstart = i\n\t\t\tcount = 1\n\t\t}\n\t}\n\n\t// large group 出现在字符串末尾位置\n\tif 3 <= count && S[start] == S[len(S)-1] {\n\t\tans = append(ans, []int{start, len(S) - 1})\n\t}\n\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/leetcode/830/ac830_test.go",
    "content": "package problem830\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_largeGroupPositions(t *testing.T) {\n\tstr1 := \"abbxxxxzzy\"\n\tfmt.Println(largeGroupPositions(str1))\n\n\tstr2 := \"abc\"\n\tfmt.Println(largeGroupPositions(str2))\n\n\tstr3 := \"abcdddeeeeaabbbcd\"\n\tfmt.Println(largeGroupPositions(str3))\n\n\tstr4 := \"aaa\"\n\tfmt.Println(largeGroupPositions(str4))\n}\n"
  },
  {
    "path": "algorithm/leetcode/832/ac832.go",
    "content": "package problem832\n\nfunc flipAndInvertImage(A [][]int) [][]int {\n\tfor i := 0; i < len(A); i++ {\n\t\treverse(A[i])\n\t\tinvert(A[i])\n\t}\n\treturn A\n}\n\nfunc reverse(array []int) {\n\tfor left, right := 0, len(array)-1; left < right; {\n\t\tarray[left], array[right] = array[right], array[left]\n\t\tleft++\n\t\tright--\n\t}\n}\n\nfunc invert(array []int) {\n\tfor i := 0; i < len(array); i++ {\n\t\tif 1 == array[i] {\n\t\t\tarray[i] = 0\n\t\t} else if 0 == array[i] {\n\t\t\tarray[i] = 1\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "algorithm/leetcode/836/ac836.go",
    "content": "package problem836\n\n// 两个矩形 A B 有重叠部分,当且仅当\n// A.bottom < B.top && A.left < B.right and B.bottom < A.top && B.left < A.right\nfunc isRectangleOverlap(rec1 []int, rec2 []int) bool {\n\tif rec1[1] < rec2[3] && rec1[0] < rec2[2] && rec2[1] < rec1[3] && rec2[0] < rec1[2] {\n\t\treturn true\n\t}\n\treturn false\n}\n"
  },
  {
    "path": "algorithm/leetcode/840/ac840.go",
    "content": "package problem840\n\nfunc numMagicSquaresInside(grid [][]int) int {\n\tif len(grid) < 3 { return 0 }\n\tres := 0\n\tfor i:=1; i<len(grid)-1; i++ {\n\t\tfor j:=1; j<len(grid[0])-1; j++ {\n\t\t\tif grid[i][j] == 5 {\n\t\t\t\tis_ok := true\n\t\t\t\tm := make([]bool, 9)\n\t\t\t\tm[4] = true\n\n\t\t\t\tfor _, offset := range [][]int{[]int{-1, -1}, []int{-1, 0},\n\t\t\t\t\t[]int{-1, 1}, []int{0, -1}} {\n\t\t\t\t\tv1,v2 := grid[i+offset[0]][j+offset[1]], grid[i-offset[0]][j-offset[1]]\n\t\t\t\t\tif v1<1 || v1>9 || v2<1 || v2>9 ||\n\t\t\t\t\t\tv1+v2 != 10 || m[v1-1] == true || m[v2-1] == true {\n\t\t\t\t\t\tis_ok = false\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tm[v1-1], m[v2-1] = true, true\n\t\t\t\t}\n\t\t\t\tif is_ok == true { res++ }\n\t\t\t}\n\t\t}\n\t}\n\treturn res\n}\n"
  },
  {
    "path": "algorithm/leetcode/844/ac844.go",
    "content": "package problem844\n\nfunc backspaceCompare(S string, T string) bool {\n\tnewS := core(S)\n\tnewT := core(T)\n\n\tif newS == newT {\n\t\treturn true\n\t}\n\treturn false\n}\n\nfunc core(s string) string {\n\tans := make([]byte, 0)\n\tfor i := 0; i < len(s); i++ {\n\t\tif '#' == s[i] {\n\t\t\tif 0 < len(ans) {\n\t\t\t\tans = ans[0 : len(ans)-1]\n\t\t\t}\n\t\t} else {\n\t\t\tans = append(ans, s[i])\n\t\t}\n\t}\n\treturn string(ans)\n}\n"
  },
  {
    "path": "algorithm/sfo/30/ac30.go",
    "content": "package problem30\n\nimport (\n\t\"github.com/emirpasic/gods/stacks/arraystack\"\n\t\"errors\"\n)\n\nvar (\n\tdataStack = arraystack.New()\n\tminStack  = arraystack.New()\n)\n\nfunc push(number int) {\n\tdataStack.Push(number)\n\n\tif 0 == minStack.Size() {\n\t\tminStack.Push(number)\n\t} else {\n\t\ttopNumber, _ := minStack.Peek()\n\t\ttopN := topNumber.(int)\n\n\t\tif number < topN {\n\t\t\tminStack.Push(number)\n\t\t} else {\n\t\t\tminStack.Push(topN)\n\t\t}\n\t}\n}\n\nfunc pop() {\n\tif 0 < dataStack.Size() && 0 < minStack.Size() {\n\t\tdataStack.Pop()\n\t\tminStack.Pop()\n\t}\n}\n\nfunc min() (int, error) {\n\tif 0 < dataStack.Size() && 0 < minStack.Size() {\n\t\ttopNumber, _ := minStack.Pop()\n\t\ttopN := topNumber.(int)\n\t\treturn topN, nil\n\t}\n\treturn 0, errors.New(\"栈为空\")\n}\n"
  },
  {
    "path": "algorithm/sfo/30/ac30_test.go",
    "content": "package problem30\n\nimport (\n\t\"testing\"\n\t\"github.com/stretchr/testify/assert\"\n)\n\nfunc TestOk(t *testing.T) {\n\tast := assert.New(t)\n\n\tpush(3)\n\tpush(4)\n\tpush(2)\n\tpush(6)\n\tpush(5)\n\tpop()\n\n\tminNumber, ok := min()\n\tif nil != ok {\n\t\tast.Error(ok)\n\t}\n\tast.Equal(2, minNumber, \"栈中最小数\")\n}\n"
  },
  {
    "path": "algorithm/sfo/31/ac31.go",
    "content": "package problem31\n\nimport \"github.com/emirpasic/gods/stacks/arraystack\"\n\nfunc isPopOrder(pushStack, popStack []int) bool {\n\tlength := len(pushStack)\n\tif 0 == length || length != len(popStack) {\n\t\treturn false\n\t}\n\n\tstack := arraystack.New()\n\tnextPush, nextPop := 0, 0\n\n\tfor nextPop < length {\n\t\tfor topNumber, _ := stack.Peek(); nil == topNumber || topNumber != popStack[nextPop]; {\n\t\t\tif nextPush == length {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tstack.Push(pushStack[nextPush])\n\t\t\tnextPush++\n\n\t\t\ttopNumber, _ = stack.Peek()\n\t\t}\n\t\tif topNumber, _ := stack.Peek(); topNumber != popStack[nextPop] {\n\t\t\tbreak\n\t\t}\n\n\t\tstack.Pop()\n\t\tnextPop++\n\t}\n\n\tif stack.Empty() && nextPop == length {\n\t\treturn true\n\t}\n\treturn false\n}\n\nfunc Ma(){\n\treturn\n}\n"
  },
  {
    "path": "algorithm/sfo/31/ac31_test.go",
    "content": "package problem31\n\nimport (\n\t\"testing\"\n\t\"github.com/stretchr/testify/assert\"\n)\n\nfunc Test_isPopOrder(t *testing.T) {\n\ttype argument struct {\n\t\tpushStack []int\n\t\tpopStack  []int\n\t}\n\ttype answer struct {\n\t\tvalue bool\n\t}\n\ttype example struct {\n\t\targ argument\n\t\tans answer\n\t}\n\n\texamples := []example{\n\t\t{\n\t\t\targ: argument{\n\t\t\t\tpushStack: []int{1, 2, 3, 4, 5},\n\t\t\t\tpopStack:  []int{4, 5, 3, 2, 1},\n\t\t\t},\n\t\t\tans: answer{\n\t\t\t\tvalue: true,\n\t\t\t},\n\t\t}, {\n\t\t\targ: argument{\n\t\t\t\tpushStack: []int{1, 2, 3, 4, 5},\n\t\t\t\tpopStack:  []int{4, 3, 5, 1, 2},\n\t\t\t},\n\t\t\tans: answer{\n\t\t\t\tvalue: false,\n\t\t\t},\n\t\t},\n\t}\n\n\tast := assert.New(t)\n\tfor _, exam := range examples {\n\t\tast.Equal(exam.ans.value, isPopOrder(exam.arg.pushStack, exam.arg.popStack),\n\t\t\t\"压入栈:%v 弹出栈:%v\", exam.arg.pushStack, exam.arg.popStack)\n\t}\n\n}\n"
  },
  {
    "path": "algorithm/sfo/32/ac32.go",
    "content": "package problem32\n\nimport (\n\t\"gopkg.in/oleiade/lane.v1\"\n\t\"fmt\"\n)\n\ntype binaryTreeNode struct {\n\tvalue int\n\tleft  *binaryTreeNode\n\tright *binaryTreeNode\n}\n\nfunc breadthFirstSearch(root *binaryTreeNode) {\n\tif nil == root {\n\t\treturn\n\t}\n\tl := list.New()\n\tl.PushBack(root)\n\tfor l.Len() != 0 {\n\t\te := l.Front()\n\t\tl.Remove(e)\n\t\tt := e.Value.(*binaryTreeNode)\n\t\tfmt.Print(t.value, \" \")\n\t\tif t.left != nil {\n\t\t\tl.PushBack(t.left)\n\t\t}\n\t\tif t.right != nil {\n\t\t\tl.PushBack(t.right)\n\t\t}\n\t}\n}\n\n// 分行打印二叉树\nfunc breadthFirstSearch2(root *binaryTreeNode) {\n\tif nil == root {\n\t\treturn\n\t}\n\tl := list.New()\n\tl.PushBack(root)\n\ttoBePrint := 1\n\tnextLevel := 0\n\tfor l.Len() != 0 {\n\t\te := l.Front()\n\t\tl.Remove(e)\n\t\tt := e.Value.(*binaryTreeNode)\n\t\tfmt.Printf(\"%d \",t.value)\n\t\ttoBePrint--\n\t\tif t.left != nil {\n\t\t\tl.PushBack(t.left)\n\t\t\tnextLevel++\n\t\t}\n\t\tif t.right != nil {\n\t\t\tl.PushBack(t.right)\n\t\t\tnextLevel++\n\t\t}\n\t\tif toBePrint == 0 {\n\t\t\tfmt.Printf(\"\\n\")\n\t\t\ttoBePrint = nextLevel\n\t\t\tnextLevel = 0\n\t\t}\n\t}\n\n}\n"
  },
  {
    "path": "algorithm/sfo/32/ac32_test.go",
    "content": "package problem32\n\nimport \"testing\"\n\nfunc Test_breadthFirstSearch(t *testing.T) {\n\tvar node6 = binaryTreeNode{value: 11, left: nil, right: nil}\n\tvar node5 = binaryTreeNode{value: 9, left: nil, right: nil}\n\tvar node4 = binaryTreeNode{value: 7, left: nil, right: nil}\n\tvar node3 = binaryTreeNode{value: 5, left: nil, right: nil}\n\tvar node2 = binaryTreeNode{value: 10, left: &node5, right: &node6}\n\tvar node1 = binaryTreeNode{value: 6, left: &node3, right: &node4}\n\tvar node0 = binaryTreeNode{value: 8, left: &node1, right: &node2}\n\n\tbreadthFirstSearch(&node0)\n\n\tbreadthFirstSearch2(&node0)\n}\n"
  },
  {
    "path": "algorithm/sfo/33/ac33.go",
    "content": "package problem33\n\n// begin 开始字符的序号， end 结尾字符的序号\nfunc verifySquenceOfBST(sequence []int, begin, end int) bool {\n\tif nil == sequence || begin >= end {\n\t\treturn false\n\t}\n\n\troot := sequence[end]\n\n\t// 二叉搜索树中，左子树节点的值小于根节点的值\n\ti := begin\n\tfor ; i < end; i++ {\n\t\tif sequence[i] > root {\n\t\t\tbreak\n\t\t}\n\t}\n\t// 二叉搜索树中，右子树节点的值大于根节点的值\n\tj := i\n\tfor ; j < end; j++ {\n\t\tif sequence[j] < root {\n\t\t\treturn false\n\t\t}\n\t}\n\t// 判断左子树是不是二叉搜索树\n\tleft := true\n\tif 1 < i-begin {\n\t\tleft = verifySquenceOfBST(sequence, begin, i-1)\n\t}\n\t// 判断右子树是不是二叉搜索树\n\tright := true\n\tif 1 < end-i {\n\t\tright = verifySquenceOfBST(sequence, i, end-1)\n\t}\n\n\treturn left && right\n}\n"
  },
  {
    "path": "algorithm/sfo/33/ac33_test.go",
    "content": "package problem33\n\nimport (\n\t\"testing\"\n\t\"github.com/stretchr/testify/assert\"\n)\n\nfunc Test_verifySquenceOfBST(t *testing.T) {\n\tast := assert.New(t)\n\tast.Equal(true, verifySquenceOfBST([]int{5, 7, 6, 9, 11, 10, 8}, 0, 6),\n\t\t\"是二叉搜索树的后序遍历序列\")\n\tast.Equal(false, verifySquenceOfBST([]int{7, 4, 6, 5}, 0, 3),\n\t\t\"不是二叉搜索树的后序遍历序列\")\n}\n"
  },
  {
    "path": "algorithm/sfo/34/ac34.go",
    "content": "package problem34\n\nimport (\n\t\"github.com/emirpasic/gods/stacks/arraystack\"\n\t\"fmt\"\n)\n\ntype binaryTreeNode struct {\n\tvalue int\n\tleft  *binaryTreeNode\n\tright *binaryTreeNode\n}\n\nfunc findPath(root *binaryTreeNode, expectedSum int) {\n\tif nil == root {\n\t\treturn\n\t}\n\tstack := arraystack.New()\n\tcurrentSum := 0\n\tfindPathCore(root, stack, expectedSum, currentSum)\n}\n\nfunc findPathCore(root *binaryTreeNode, stack *arraystack.Stack, expectedSum, currentSum int) {\n\tcurrentSum += root.value\n\tstack.Push(root.value)\n\n\t// 如果是叶节点，并且路径节点值的和等于输入的期望值则打印路径\n\tisLeaf := root.left == nil && root.right == nil\n\tif isLeaf && currentSum == expectedSum {\n\t\tit := stack.Iterator()\n\t\tfor it.End(); it.Prev(); {\n\t\t\tfmt.Print(it.Value(), \" \")\n\t\t}\n\t\tfmt.Printf(\"\\n\")\n\t}\n\n\t// 如果不是叶节点，则遍历它的子节点\n\tif root.left != nil {\n\t\tfindPathCore(root.left, stack, expectedSum, currentSum)\n\t}\n\tif root.right != nil {\n\t\tfindPathCore(root.right, stack, expectedSum, currentSum)\n\t}\n\tstack.Pop()\n}\n"
  },
  {
    "path": "algorithm/sfo/34/ac34_test.go",
    "content": "package problem34\n\nimport (\n\t\"testing\"\n)\n\nfunc Test_findPath(t *testing.T) {\n\tnode4 := binaryTreeNode{value: 4, left: nil, right: nil}\n\tnode7 := binaryTreeNode{value: 7, left: nil, right: nil}\n\tnode5 := binaryTreeNode{value: 5, left: &node4, right: &node7}\n\tnode12 := binaryTreeNode{value: 12, left: nil, right: nil}\n\tnode10 := binaryTreeNode{value: 10, left: &node5, right: &node12}\n\n\tfindPath(&node10, 22)\n}\n"
  },
  {
    "path": "algorithm/sfo/35/ac35.go",
    "content": "package problem35\n\ntype complexListNode struct {\n\tvalue   int\n\tnext    *complexListNode\n\tsibling *complexListNode\n}\n\nfunc cloneNodes(head *complexListNode) {\n\tpNode := head\n\tfor nil != pNode {\n\t\tpCloned := new(complexListNode)\n\t\tpCloned.value = pNode.value\n\t\tpCloned.next = pNode.next\n\t\tpNode.next = pCloned\n\t\tpNode = pCloned.next\n\t}\n\n}\n\nfunc connectSiblingNodes(head *complexListNode) {\n\tpNode := head\n\tfor nil != pNode {\n\t\tpCloned := pNode.next\n\t\tif nil != pNode.sibling {\n\t\t\tpCloned.sibling = pNode.sibling.next\n\t\t}\n\t\tpNode = pCloned.next\n\t}\n}\n\nfunc reconnectNodes(head *complexListNode) *complexListNode {\n\tpNode := head\n\tvar pClonedHead, pClonedNode *complexListNode\n\tif nil != pNode {\n\t\tpClonedHead = pNode.next\n\t\tpClonedNode = pClonedHead\n\t\tpNode.next = pClonedNode.next\n\t\tpNode = pNode.next\n\t}\n\n\tfor nil != pNode {\n\t\tpClonedNode.next = pNode.next\n\t\tpClonedNode = pClonedNode.next\n\t\tpNode.next = pClonedNode.next\n\t\tpNode = pNode.next\n\t}\n\treturn pClonedHead\n}\n\nfunc clone(pHead *complexListNode) *complexListNode {\n\tcloneNodes(pHead)\n\tconnectSiblingNodes(pHead)\n\treturn reconnectNodes(pHead)\n}\n"
  },
  {
    "path": "algorithm/sfo/36/ac36.go",
    "content": "package problem36\n\ntype binaryTreeNode struct {\n\tvalue       int\n\tleft, right *binaryTreeNode\n}\n\nfunc conver(root *binaryTreeNode) *binaryTreeNode {\n\tvar lastNodeInList *binaryTreeNode\n\tconvertNode(root, &lastNodeInList)\n\n\t// lastNodeInList指向双向链表的尾节点，但是需要返回链表的头结点，所以进行下面操作。\n\theadOfList := lastNodeInList\n\tfor nil != headOfList && nil != headOfList.left {\n\t\theadOfList = headOfList.left\n\t}\n\treturn headOfList\n}\n\nfunc convertNode(node *binaryTreeNode, lastNodeInList **binaryTreeNode) {\n\tif nil == node {\n\t\treturn\n\t}\n\tcurrent := node\n\tif nil != current.left {\n\t\tconvertNode(current.left, lastNodeInList)\n\t}\n\tcurrent.left = *lastNodeInList\n\tif nil != *lastNodeInList {\n\t\t(*lastNodeInList).right = current\n\t}\n\t*lastNodeInList = current\n\tif nil != current.right {\n\t\tconvertNode(current.right, lastNodeInList)\n\t}\n}\n"
  },
  {
    "path": "algorithm/sfo/36/ac36_test.go",
    "content": "package problem36\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_conver(t *testing.T) {\n\tnode16 := binaryTreeNode{value: 16, left: nil, right: nil}\n\tnode12 := binaryTreeNode{value: 12, left: nil, right: nil}\n\tnode8 := binaryTreeNode{value: 8, left: nil, right: nil}\n\tnode4 := binaryTreeNode{value: 4, left: nil, right: nil}\n\tnode14 := binaryTreeNode{value: 14, left: &node12, right: &node16}\n\tnode6 := binaryTreeNode{value: 6, left: &node4, right: &node8}\n\tnode10 := binaryTreeNode{value: 10, left: &node6, right: &node14}\n\n\tptr := conver(&node10)\n\tfmt.Println(ptr.value)\n\n}\n"
  },
  {
    "path": "algorithm/sfo/38/ac38.go",
    "content": "package problem38\n\nimport \"fmt\"\n\nfunc permutation(arrayChar []byte, start int) {\n\tif 1 >= len(arrayChar) {\n\t\treturn\n\t}\n\tif start == len(arrayChar)-1 {\n\t\tfor i := 0; i < len(arrayChar); i++ {\n\t\t\tfmt.Printf(\"%c\", arrayChar[i])\n\t\t}\n\t\tfmt.Println()\n\t} else {\n\t\tfor i := start; i < len(arrayChar); i++ {\n\t\t\tswap(arrayChar, start, i)\n\t\t\tpermutation(arrayChar, start+1)\n\t\t\tswap(arrayChar, start, i)\n\t\t}\n\t}\n}\n\nfunc swap(array []byte, m, n int) {\n\ttemp := array[m]\n\tarray[m] = array[n]\n\tarray[n] = temp\n}\n"
  },
  {
    "path": "algorithm/sfo/38/ac38_test.go",
    "content": "package problem38\n\nimport \"testing\"\n\nfunc Test_permutation(t *testing.T) {\n\tarrayChar := []byte(\"abc\")\n\tpermutation(arrayChar, 0)\n}\n"
  },
  {
    "path": "algorithm/sfo/39/ac39.go",
    "content": "package problem39\n\nfunc moreThanHalfNum(numbers []int) int {\n\tif nil == numbers || 0 >= len(numbers) {\n\t\treturn 0\n\t}\n\tans := numbers[0]\n\ttimes := 1\n\tfor i := 1; i < len(numbers); i++ {\n\t\tif 0 == times {\n\t\t\tans = numbers[i]\n\t\t\ttimes = 1\n\t\t} else if ans == numbers[i] {\n\t\t\ttimes++\n\t\t} else {\n\t\t\ttimes--\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/sfo/39/ac39_test.go",
    "content": "package problem39\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_moreThanHalfNum(t *testing.T) {\n\tnumbers := []int{0, 0, 0, 1, 1, 1, 2, 3, 1, 1, 1}\n\n\tfmt.Println(moreThanHalfNum(numbers))\n}\n"
  },
  {
    "path": "algorithm/sfo/40/ac40.go",
    "content": "package problem40\n\nimport \"sort\"\n\nfunc getLeastNumbers(data []int, k int) []int {\n\tif nil == data || k > len(data) {\n\t\treturn nil\n\t}\n\tleastNumbers := make([]int, k)\n\tfor i := 0; i < k; i++ {\n\t\tleastNumbers[i] = data[i]\n\t}\n\tsort.Ints(leastNumbers)\n\n\tfor i:=k; i<len(data); i++ {\n\t\tif data[i] < leastNumbers[k-1] {\n\t\t\tleastNumbers[k-1] = data[i]\n\t\t\tsort.Ints(leastNumbers)\n\t\t}\n\t}\n\treturn leastNumbers\n}\n"
  },
  {
    "path": "algorithm/sfo/40/ac40_test.go",
    "content": "package problem40\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_getLeastNumbers(t *testing.T) {\n\tnumbers := []int{10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}\n\n\tans := getLeastNumbers(numbers, 3)\n\tfor _, value := range ans {\n\t\tfmt.Println(value)\n\t}\n\n}\n"
  },
  {
    "path": "algorithm/sfo/42/ac42.go",
    "content": "package problem42\n\nfunc findGreatestSumOfSubArray(data []int) (int, bool) {\n\tif nil == data || len(data) <= 0 {\n\t\treturn 0, false\n\t}\n\tvar currentSum, greatestSum int\n\tfor i := 0; i < len(data); i++ {\n\t\tif currentSum <= 0 {\n\t\t\tcurrentSum = data[i]\n\t\t} else {\n\t\t\tcurrentSum += data[i]\n\t\t}\n\t\tif currentSum > greatestSum {\n\t\t\tgreatestSum = currentSum\n\t\t}\n\t}\n\treturn greatestSum, true\n}\n"
  },
  {
    "path": "algorithm/sfo/42/ac42_test.go",
    "content": "package problem42\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findGreatestSumOfSubArray(t *testing.T) {\n\tdata := []int{1, -2, 3, 10, -4, 7, 2, -5}\n\n\tfmt.Println(findGreatestSumOfSubArray(data))\n\n}\n"
  },
  {
    "path": "algorithm/sfo/43/ac43.go",
    "content": "package problem43\n\n// 1~n 整数中 1 出现的次数 http://blog.csdn.net/yi_afly/article/details/52012593\nfunc numberOf1Between1AndN(n int) int {\n\tans := 0\n\tfor i := 1; i <= n; i *= 10 {\n\t\ta := n / i\n\t\tb := n % i\n\t\tif 0 == a%10 {\n\t\t\tans += i * a / 10\n\t\t} else if 1 == a%10 {\n\t\t\tans += i*a/10 + b + 1\n\t\t} else {\n\t\t\tans += (a/10 + 1) * i\n\t\t}\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/sfo/43/ac43_test.go",
    "content": "package problem43\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_numberOf1Between1AndN(t *testing.T) {\n\tfmt.Println(numberOf1Between1AndN(12))\n}\n"
  },
  {
    "path": "algorithm/sfo/44/ac44.go",
    "content": "package problem44\n\nimport \"math\"\n\nfunc countOfIntegers(digits int) int {\n\tif 1 == digits {\n\t\treturn 10\n\t}\n\treturn int(9 * math.Pow10(digits-1))\n}\n\nfunc beginNumber(digits int) int {\n\tif 1 == digits {\n\t\treturn 0\n\t}\n\treturn int(math.Pow10(digits - 1))\n}\n\nfunc digitAtIndexCore(index, digits int) int {\n\tnumber := beginNumber(digits) + index/digits\n\tindexFromRight := digits - index%digits\n\tfor i := 1; i < indexFromRight; i++ {\n\t\tnumber /= 10\n\t}\n\treturn number % 10\n}\n\nfunc digitAtIndex(index int) int {\n\tif 0 > index {\n\t\treturn -1\n\t}\n\tdigit := 1\n\tfor {\n\t\tnumbers := countOfIntegers(digit)\n\t\tif index < numbers*digit {\n\t\t\treturn digitAtIndexCore(index, digit)\n\t\t}\n\t\tindex -= digit * numbers\n\t\tdigit++\n\t}\n\treturn -1\n}\n"
  },
  {
    "path": "algorithm/sfo/44/ac44_test.go",
    "content": "package problem44\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_digitAtIndex(t *testing.T) {\n\tfmt.Println(digitAtIndex(19))\n}\n"
  },
  {
    "path": "algorithm/sfo/45/ac45.go",
    "content": "package problem45\n\nimport (\n\t\"sort\"\n\t\"strconv\"\n)\n\ntype intSlice []int\n\nfunc (p intSlice) Len() int {\n\treturn len(p)\n}\n\nfunc (p intSlice) Less(i, j int) bool {\n\treturn strconv.Itoa(p[i])+strconv.Itoa(p[j]) < strconv.Itoa(p[j])+strconv.Itoa(p[i])\n}\n\nfunc (p intSlice) Swap(i, j int) {\n\tp[i], p[j] = p[j], p[i]\n}\n\nfunc printMinNumber(numbers []int) string {\n\tif nil == numbers {\n\t\treturn \"\"\n\t}\n\n\tsort.Sort(intSlice(numbers))\n\tvar ans string\n\tfor _, value := range numbers {\n\t\tans += strconv.Itoa(value)\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/sfo/45/ac45_test.go",
    "content": "package problem45\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_printMinNumber(t *testing.T) {\n\tnumbers := []int{3, 32, 321}\n\tfmt.Println(printMinNumber(numbers))\n}\n"
  },
  {
    "path": "algorithm/sfo/46/ac46.go",
    "content": "package problem46\n\nimport \"strconv\"\n\nfunc getTranslation(number int) int {\n\tif 0 > number {\n\t\treturn 0\n\t}\n\treturn getTranslationCore(strconv.Itoa(number))\n}\n\nfunc getTranslationCore(str string) int {\n\tlength := len(str)\n\tcounts := make([]int, length)\n\tnum := 0\n\n\tfor i := length - 1; i >= 0; i-- {\n\t\tnum = 0\n\t\tif i < length-1 {\n\t\t\tnum = counts[i+1]\n\t\t} else {\n\t\t\tnum = 1\n\t\t}\n\n\t\tif i < length-1 {\n\t\t\tdigit1 := str[i] - '0'\n\t\t\tdigit2 := str[i+1] - '0'\n\t\t\tnumber := digit1*10 + digit2\n\t\t\tif 10 <= number && 25 >= number {\n\t\t\t\tif i < length-2 {\n\t\t\t\t\tnum += counts[i+2]\n\t\t\t\t} else {\n\t\t\t\t\tnum += 1\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcounts[i] = num\n\t}\n\treturn counts[0]\n}\n"
  },
  {
    "path": "algorithm/sfo/46/ac46_test.go",
    "content": "package problem46\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_getTranslation(t *testing.T) {\n\tfmt.Println(getTranslation(12258))\n}\n"
  },
  {
    "path": "algorithm/sfo/47/ac47.go",
    "content": "package problem47\n\nfunc getMaxValue(matrix [][]int) int {\n\tif nil == matrix {\n\t\treturn 0\n\t}\n\n\trows := len(matrix)\n\tcolumns := len(matrix[0])\n\tdp := make([][]int, rows)\n\n\tfor i := 0; i < rows; i++ {\n\t\tdp[i] = make([]int, columns)\n\t\tfor j := 0; j < columns; j++ {\n\t\t\tif 0 == i && 0 == j {\n\t\t\t\tdp[i][j] = matrix[i][j]\n\t\t\t}\n\t\t\tif 0 == i && 0 != j {\n\t\t\t\tdp[i][j] = dp[i][j-1] + matrix[i][j]\n\t\t\t}\n\t\t\tif 0 != i && 0 == j {\n\t\t\t\tdp[i][j] = dp[i-1][j] + matrix[i][j]\n\t\t\t}\n\t\t\tif 0 != i && 0 != j {\n\t\t\t\tif dp[i-1][j] >= dp[i][j-1] {\n\t\t\t\t\tdp[i][j] = dp[i-1][j] + matrix[i][j]\n\t\t\t\t} else {\n\t\t\t\t\tdp[i][j] = dp[i][j-1] + matrix[i][j]\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn dp[rows-1][columns-1]\n}\n\nfunc getMaxValue2(matrix [][]int) int {\n\tif nil == matrix {\n\t\treturn 0\n\t}\n\n\trows := len(matrix)\n\tcolumns := len(matrix[0])\n\tdp := make([]int, columns)\n\tfor i := 0; i < rows; i++ {\n\t\tfor j := 0; j < columns; j++ {\n\t\t\tleft, up := 0, 0\n\t\t\tif 0 < i {\n\t\t\t\tup = dp[j]\n\t\t\t}\n\t\t\tif 0 < j {\n\t\t\t\tleft = dp[j-1]\n\t\t\t}\n\n\t\t\tif left >= up {\n\t\t\t\tdp[j] = left + matrix[i][j]\n\t\t\t} else {\n\t\t\t\tdp[j] = up + matrix[i][j]\n\t\t\t}\n\t\t}\n\t}\n\treturn dp[columns-1]\n}\n"
  },
  {
    "path": "algorithm/sfo/47/ac47_test.go",
    "content": "package problem47\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_getMaxValue(t *testing.T) {\n\tmatrix := [][]int{\n\t\t{1, 3, 3},\n\t\t{2, 1, 3},\n\t\t{2, 2, 1},\n\t}\n\tfmt.Println(getMaxValue(matrix))\n\tfmt.Println(getMaxValue2(matrix))\n}\n"
  },
  {
    "path": "algorithm/sfo/48/ac48.go",
    "content": "package problem48\n\nfunc longestSubstring(str string) int {\n\tcurLength, maxLength := 0, 0\n\tposition := make([]int, 26)\n\tfor i := 0; i < 26; i++ {\n\t\tposition[i] = -1\n\t}\n\n\tfor i := 0; i < len(str); i++ {\n\t\tpreIndex := position[str[i]-'a']\n\t\tif 0 > preIndex || i-preIndex > curLength {\n\t\t\tcurLength++\n\t\t} else {\n\t\t\tif curLength > maxLength {\n\t\t\t\tmaxLength = curLength\n\t\t\t}\n\t\t\tcurLength = i - preIndex\n\t\t}\n\t\tposition[str[i]-'a'] = i\n\t\tif curLength > maxLength {\n\t\t\tmaxLength = curLength\n\t\t}\n\t}\n\treturn maxLength\n}\n"
  },
  {
    "path": "algorithm/sfo/48/ac48_test.go",
    "content": "package problem48\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_longestSubstring(t *testing.T) {\n\tfmt.Println(longestSubstring(\"arabcacfr\"))\n}\n"
  },
  {
    "path": "algorithm/sfo/49/ac49.go",
    "content": "package problem49\n\nfunc getUglyNumber(index int) int {\n\tif 0 >= index {\n\t\treturn 0\n\t}\n\n\tuglyNumbers := make([]int, index)\n\tuglyNumbers[0] = 1\n\tnextUglyIndex := 1\n\n\tvar pMultiply2, pMultiply3, pMultiply5 int\n\tfor nextUglyIndex < index {\n\t\tuglyNumbers[nextUglyIndex] = min3(uglyNumbers[pMultiply2]*2, uglyNumbers[pMultiply3]*3, uglyNumbers[pMultiply5]*5)\n\n\t\tfor uglyNumbers[pMultiply2]*2 <= uglyNumbers[nextUglyIndex] {\n\t\t\tpMultiply2++\n\t\t}\n\t\tfor uglyNumbers[pMultiply3]*3 <= uglyNumbers[nextUglyIndex] {\n\t\t\tpMultiply3++\n\t\t}\n\t\tfor uglyNumbers[pMultiply5]*5 <= uglyNumbers[nextUglyIndex] {\n\t\t\tpMultiply5++\n\t\t}\n\t\tnextUglyIndex++\n\t}\n\treturn uglyNumbers[index-1]\n}\n\nfunc min3(num1, num2, num3 int) int {\n\tnumber := min(num1, num2)\n\treturn min(num3, number)\n}\n\nfunc min(num1, num2 int) int {\n\tif num1 < num2 {\n\t\treturn num1\n\t}\n\treturn num2\n}\n"
  },
  {
    "path": "algorithm/sfo/49/ac49_test.go",
    "content": "package problem49\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_getUglyNumber(t *testing.T) {\n\tfmt.Println(getUglyNumber(1500))\n}\n"
  },
  {
    "path": "algorithm/sfo/50/ac50.go",
    "content": "package problem50\n\nfunc firstNoRepeatingChar(str string) byte {\n\tif 0 >= len(str) {\n\t\treturn 0\n\t}\n\n\ttable := make([]int, 256)\n\tfor i := 0; i < len(str); i++ {\n\t\ttable[str[i]]++\n\t}\n\tfor id, value := range table {\n\t\tif 1 == value {\n\t\t\treturn byte(id)\n\t\t}\n\t}\n\treturn 0\n}\n"
  },
  {
    "path": "algorithm/sfo/50/ac50_test.go",
    "content": "package problem50\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_firstNoRepeatingChar(t *testing.T) {\n\tstr := \"abaccdeff\"\n\tans := firstNoRepeatingChar(str)\n\tfmt.Printf(\"%c %v\", ans, ans)\n}\n"
  },
  {
    "path": "algorithm/sfo/51/ac51.go",
    "content": "package problem51\n\nfunc inversePairs(data []int) int {\n\tif nil == data || 0 > len(data) {\n\t\treturn 0\n\t}\n\n\tcopy := make([]int, len(data))\n\tfor id, value := range data {\n\t\tcopy[id] = value\n\t}\n\n\tcount := inversePairsCore(data, copy, 0, len(data)-1)\n\treturn count\n}\n\nfunc inversePairsCore(data, copy []int, start, end int) int {\n\tif start == end {\n\t\tcopy[start] = data[start]\n\t\treturn 0\n\t}\n\tlength := (end - start) / 2\n\tleft := inversePairsCore(copy, data, start, start+length)\n\tright := inversePairsCore(copy, data, start+length+1, end)\n\n\ti := start + length\n\tj := end\n\tindexCopy := end\n\tcount := 0\n\n\tfor i >= start && j >= start+length+1 {\n\t\tif data[i] > data[j] {\n\t\t\tcopy[indexCopy] = data[i]\n\t\t\tindexCopy--\n\t\t\ti--\n\t\t\tcount += j - start - length\n\t\t} else {\n\t\t\tcopy[indexCopy] = data[j]\n\t\t\tindexCopy--\n\t\t\tj--\n\t\t}\n\t}\n\tfor ; i >= start; i-- {\n\t\tcopy[indexCopy] = data[i]\n\t\tindexCopy--\n\t}\n\tfor ; j >= start+length+1; j-- {\n\t\tcopy[indexCopy] = data[j]\n\t\tindexCopy--\n\t}\n\treturn left + right + count\n}\n"
  },
  {
    "path": "algorithm/sfo/51/ac51_test.go",
    "content": "package problem51\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_inversePairs(t *testing.T) {\n\tdata := []int{7, 5, 6, 4}\n\tfmt.Println(inversePairs(data))\n}\n"
  },
  {
    "path": "algorithm/sfo/52/ac52.go",
    "content": "package problem52\n\ntype ListNode struct {\n\tvalue int\n\tnext  *ListNode\n}\n\nfunc findFirstCommonNode(head1, head2 *ListNode) *ListNode {\n\tlength1 := getListLength(head1)\n\tlength2 := getListLength(head2)\n\tvar lengthDif int\n\tvar listHeadLong, listHeadShort, firstCommonNode *ListNode\n\tif length1 >= length2 {\n\t\tlengthDif = length1 - length2\n\t\tlistHeadLong = head1\n\t\tlistHeadShort = head2\n\t} else {\n\t\tlengthDif = length2 - length1\n\t\tlistHeadLong = head2\n\t\tlistHeadShort = head1\n\t}\n\n\tfor i := 0; i < lengthDif; i++ {\n\t\tlistHeadLong = listHeadLong.next\n\t}\n\tfor listHeadLong != listHeadShort && nil != listHeadLong && nil != listHeadShort {\n\t\tlistHeadLong = listHeadLong.next\n\t\tlistHeadShort = listHeadShort.next\n\t}\n\tfirstCommonNode = listHeadLong\n\treturn firstCommonNode\n}\n\nfunc getListLength(head *ListNode) int {\n\tvar length int\n\tnode := head\n\tfor nil != node {\n\t\tlength++\n\t\tnode = node.next\n\t}\n\treturn length\n}\n"
  },
  {
    "path": "algorithm/sfo/52/ac52_test.go",
    "content": "package problem52\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findFirstCommonNode(t *testing.T) {\n\tnode7 := ListNode{value: 7, next: nil}\n\tnode6 := ListNode{value: 6, next: &node7}\n\tnode5 := ListNode{value: 5, next: &node6}\n\tnode4 := ListNode{value: 4, next: &node5}\n\tnode3 := ListNode{value: 3, next: &node6}\n\tnode2 := ListNode{value: 2, next: &node3}\n\tnode1 := ListNode{value: 1, next: &node2}\n\n\tfmt.Println(findFirstCommonNode(&node1, &node4).value)\n\n}\n"
  },
  {
    "path": "algorithm/sfo/53/ac53.go",
    "content": "package problem53\n\nfunc getFirstK(numbers []int, k, start, end int) int {\n\tif start > end {\n\t\treturn -1\n\t}\n\n\tmiddleIndex := (start + end) / 2\n\tmiddleData := numbers[middleIndex]\n\tif middleData == k {\n\t\tif (0 < middleIndex && numbers[middleIndex-1] != k) || 0 == middleIndex {\n\t\t\treturn middleIndex\n\t\t} else {\n\t\t\tend = middleIndex - 1\n\t\t}\n\t} else if middleData > k {\n\t\tend = middleIndex - 1\n\t} else {\n\t\tstart = middleIndex + 1\n\t}\n\treturn getFirstK(numbers, k, start, end)\n}\n\nfunc getLastK(numbers []int, k, start, end int) int {\n\tif start > end {\n\t\treturn -1\n\t}\n\n\tmiddleIndex := (start + end) / 2\n\tmiddleData := numbers[middleIndex]\n\tif middleData == k {\n\t\tif (len(numbers)-1 > middleIndex && numbers[middleIndex+1] != k) || len(numbers)-1 == middleIndex {\n\t\t\treturn middleIndex\n\t\t} else {\n\t\t\tstart = middleIndex + 1\n\t\t}\n\t} else if middleData < k {\n\t\tstart = middleIndex + 1\n\t} else {\n\t\tend = middleIndex - 1\n\t}\n\treturn getLastK(numbers, k, start, end)\n}\n\nfunc getNumberOfK(numbers []int, k int) int {\n\tif nil == numbers {\n\t\treturn 0\n\t}\n\tfirst := getFirstK(numbers, k, 0, len(numbers)-1)\n\tlast := getLastK(numbers, k, 0, len(numbers)-1)\n\tif first > -1 && last > -1 {\n\t\treturn last - first + 1\n\t}\n\treturn 0\n}\n\nfunc getMissingNumber(numbers []int) int {\n\tif nil == numbers || len(numbers) <= 0 {\n\t\treturn -1\n\t}\n\tleft, right := 0, len(numbers)-1\n\tfor left <= right {\n\t\tmiddle := (left + right) >> 1\n\t\tif numbers[middle] != middle {\n\t\t\tif 0 == middle || numbers[middle-1] == middle-1 {\n\t\t\t\treturn middle\n\t\t\t}\n\t\t\tright = middle - 1\n\t\t} else {\n\t\t\tleft = middle + 1\n\t\t}\n\t}\n\tif left == len(numbers) {\n\t\treturn len(numbers)\n\t}\n\treturn -1\n}\n\nfunc getNumberSameAsIndex(numbers []int) int {\n\tif nil == numbers {\n\t\treturn -1\n\t}\n\n\tleft, right := 0, len(numbers)-1\n\tfor left <= right {\n\t\tmiddle := (left + right) / 2\n\t\tif numbers[middle] == middle {\n\t\t\treturn middle\n\t\t} else if numbers[middle] > middle {\n\t\t\tright = middle - 1\n\t\t} else {\n\t\t\tleft = middle + 1\n\t\t}\n\t}\n\treturn -1\n}\n"
  },
  {
    "path": "algorithm/sfo/53/ac53_test.go",
    "content": "package problem53\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_getNumberOfK(t *testing.T) {\n\tnumbers := []int{1, 2, 3, 3, 3, 3, 4, 5}\n\tk := 3\n\tfmt.Println(getNumberOfK(numbers, k))\n}\n"
  },
  {
    "path": "algorithm/sfo/54/ac54.go",
    "content": "package problem54\n\ntype BinaryTreeNode struct {\n\tvalue       int\n\tleft, right *BinaryTreeNode\n}\n\nfunc kthNode(root *BinaryTreeNode, k int) *BinaryTreeNode {\n\tif nil == root || k <= 0 {\n\t\treturn nil\n\t}\n\n\tvar target *BinaryTreeNode\n\tif root.left != nil {\n\t\ttarget = kthNode(root.left, k)\n\t}\n\n\tif target == nil {\n\t\tif 1 == k {\n\t\t\ttarget = root\n\t\t} else {\n\t\t\tk--\n\t\t}\n\t}\n\n\tif target == nil && root.right != nil {\n\t\ttarget = kthNode(root.right, k)\n\t}\n\treturn target\n}\n"
  },
  {
    "path": "algorithm/sfo/55/ac55.go",
    "content": "package problem55\n\ntype BinaryTreeNode struct {\n\tvalue       int\n\tleft, right *BinaryTreeNode\n}\n\nfunc treeDepth(root *BinaryTreeNode) int {\n\tif nil == root {\n\t\treturn 0\n\t}\n\tleft := treeDepth(root.left)\n\tright := treeDepth(root.right)\n\tif left >= right {\n\t\treturn left + 1\n\t} else {\n\t\treturn right + 1\n\t}\n}\n\nfunc isBalanced(root *BinaryTreeNode, depth *int) bool {\n\tif nil == root {\n\t\t*depth = 0\n\t\treturn true\n\t}\n\tvar left, right int\n\tif isBalanced(root.left, &left) && isBalanced(root.right, &right) {\n\t\tdiff := left - right\n\t\tif -1 <= diff && diff <= 1 {\n\t\t\tif left > right {\n\t\t\t\t*depth = 1 + left\n\t\t\t} else {\n\t\t\t\t*depth = 1 + right\n\t\t\t}\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc isBalance(root *BinaryTreeNode) bool {\n\tvar depth int\n\treturn isBalanced(root, &depth)\n}\n"
  },
  {
    "path": "algorithm/sfo/55/ac55_test.go",
    "content": "package problem55\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_treeDepth(t *testing.T) {\n\tnode7 := BinaryTreeNode{value: 7, left: nil, right: nil}\n\tnode6 := BinaryTreeNode{value: 6, left: nil, right: nil}\n\tnode5 := BinaryTreeNode{value: 5, left: &node7, right: nil}\n\tnode4 := BinaryTreeNode{value: 4, left: nil, right: nil}\n\tnode3 := BinaryTreeNode{value: 3, left: nil, right: &node6}\n\tnode2 := BinaryTreeNode{value: 2, left: &node4, right: &node5}\n\tnode1 := BinaryTreeNode{value: 1, left: &node2, right: &node3}\n\n\tfmt.Println(treeDepth(&node1))\n\n\tfmt.Println(isBalance(&node1))\n\n}\n"
  },
  {
    "path": "algorithm/sfo/56/ac56.go",
    "content": "package problem56\n\nimport (\n\t\"unsafe\"\n\t\"errors\"\n)\n\nfunc findNumbersAppearOnce(data []int) (int, int) {\n\tif nil == data || len(data) < 2 {\n\t\treturn 0, 0\n\t}\n\n\tvar result int\n\tfor i := 0; i < len(data); i++ {\n\t\tresult ^= data[i]\n\t}\n\tindexOf1 := findFirstBitIs1(result)\n\tvar num1, num2 int\n\tfor j := 0; j < len(data); j++ {\n\t\tif isBit1(data[j], indexOf1) {\n\t\t\tnum1 ^= data[j]\n\t\t} else {\n\t\t\tnum2 ^= data[j]\n\t\t}\n\t}\n\treturn num1, num2\n}\n\nfunc findFirstBitIs1(num int) uint {\n\tvar indexBit uint\n\tfor (0 == num&1) && (indexBit < uint(unsafe.Sizeof(int(0))*8)) {\n\t\tnum = num >> 1\n\t\tindexBit++\n\t}\n\treturn indexBit\n}\n\nfunc isBit1(num int, indexBit uint) bool {\n\tnum = num >> indexBit\n\tif 1 == num&1 {\n\t\treturn true\n\t}\n\treturn false\n}\n\nfunc findNumberAppearOnce2(numbers []int) int {\n\tif nil == numbers || 0 >= len(numbers) {\n\t\tpanic(errors.New(\"invalid input\"))\n\t}\n\n\tbitSum := make([]int, 32)\n\tfor i := 0; i < len(numbers); i++ {\n\t\tbitMask := 1\n\t\tfor j := 31; j >= 0; j-- {\n\t\t\tbit := numbers[i] & bitMask\n\t\t\tif 0 != bit {\n\t\t\t\tbitSum[j] += 1\n\t\t\t}\n\t\t\tbitMask = bitMask << 1\n\t\t}\n\t}\n\n\tvar result int\n\tfor i := 0; i < 32; i++ {\n\t\tresult = result << 1\n\t\tresult += bitSum[i] % 3\n\t}\n\treturn result\n}\n"
  },
  {
    "path": "algorithm/sfo/56/ac56_test.go",
    "content": "package problem56\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findNumbersAppearOnce(t *testing.T) {\n\tdata := []int{2, 4, 3, 6, 3, 2, 5, 5}\n\tfmt.Println(findNumbersAppearOnce(data))\n\n\tdata2 := []int{2, 2, 2, 3, 3, 3, 4}\n\tfmt.Println(findNumberAppearOnce2(data2))\n}\n"
  },
  {
    "path": "algorithm/sfo/57/ac57.go",
    "content": "package problem57\n\nimport \"fmt\"\n\nfunc findNumbers(data []int, sum int) (int, int, bool) {\n\tvar found bool\n\tif nil == data || 1 > len(data) {\n\t\treturn 0, 0, found\n\t}\n\n\tahead, behind := 0, len(data)-1\n\tfor ahead < behind {\n\t\tcurrentSum := data[ahead] + data[behind]\n\t\tif currentSum == sum {\n\t\t\tfound = true\n\t\t\treturn data[ahead], data[behind], found\n\t\t} else if currentSum < sum {\n\t\t\tahead++\n\t\t} else {\n\t\t\tbehind--\n\t\t}\n\t}\n\treturn 0, 0, found\n}\n\nfunc findContinuousSequence(sum int) {\n\tif 3 > sum {\n\t\treturn\n\t}\n\n\tmiddle := (sum + 1) / 2\n\tsmall, big := 1, 2\n\tcurrentSum := small + big\n\tfor small < middle {\n\t\tif currentSum == sum {\n\t\t\tprintContinuousSequence(small, big)\n\t\t}\n\n\t\tfor currentSum > sum && small < middle {\n\t\t\tcurrentSum -= small\n\t\t\tsmall++\n\n\t\t\tif currentSum == sum {\n\t\t\t\tprintContinuousSequence(small, big)\n\t\t\t}\n\t\t}\n\t\tbig++\n\t\tcurrentSum += big\n\t}\n}\n\nfunc printContinuousSequence(small, big int) {\n\tfor i := small; i <= big; i++ {\n\t\tfmt.Printf(\"%v \", i)\n\t}\n\tfmt.Println()\n}\n"
  },
  {
    "path": "algorithm/sfo/57/ac57_test.go",
    "content": "package problem57\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_findNumbers(t *testing.T) {\n\tdata := []int{1, 2, 4, 7, 11, 15}\n\tsum := 15\n\n\tfmt.Println(findNumbers(data, sum))\n\n\tfindContinuousSequence(15)\n}\n"
  },
  {
    "path": "algorithm/sfo/58/ac58.go",
    "content": "package problem58\n\nfunc reverse(str []rune) {\n\tcopyStr := str\n\n\tbegin, end := 0, len(copyStr)-1\n\tfor begin < end {\n\t\tcopyStr[begin], copyStr[end] = copyStr[end], copyStr[begin]\n\t\tbegin++\n\t\tend--\n\t}\n}\n\nfunc reverseSentence(str string) string {\n\tif len(str) < 1 {\n\t\treturn \"\"\n\t}\n\n\tcopyCharArray := []rune(str)\n\treverse(copyCharArray)\n\n\tvar begin, end int\n\tfor end <= len(copyCharArray) {\n\t\tif end == len(copyCharArray) {\n\t\t\treverse(copyCharArray[begin:end])\n\t\t\tbreak\n\t\t}\n\n\t\tif copyCharArray[end] != ' ' {\n\t\t\tend++\n\t\t} else {\n\t\t\treverse(copyCharArray[begin:end])\n\t\t\tend++\n\t\t\tbegin = end\n\t\t}\n\t}\n\treturn string(copyCharArray)\n}\n\nfunc leftRotateString(str string, n int) string {\n\tif len(str) < n {\n\t\treturn \"\"\n\t}\n\n\tcopyCharArray := []rune(str)\n\treverse(copyCharArray[0:n])\n\treverse(copyCharArray[n:])\n\treverse(copyCharArray[:])\n\n\treturn string(copyCharArray)\n}\n"
  },
  {
    "path": "algorithm/sfo/58/ac58_test.go",
    "content": "package problem58\n\nimport (\n\t\"fmt\"\n\t\"testing\"\n)\n\nfunc Test_reverseSentence(t *testing.T) {\n\ttext := \"I am a student.\"\n\n\tfmt.Println(reverseSentence(text))\n}\n\nfunc Test_leftRotateString(t *testing.T) {\n\ttext := \"abcdefg\"\n\n\tfmt.Println(leftRotateString(text, 2))\n}\n"
  },
  {
    "path": "algorithm/sfo/59/ac59.go",
    "content": "package problem59\n\nimport (\n\t\"gopkg.in/oleiade/lane.v1\"\n)\n\nfunc maxInWindows(num []int, size int) []int {\n\tmaxInWindow := lane.NewDeque()\n\n\tif len(num) >= size && size >= 1 {\n\t\tindex := lane.NewDeque()\n\t\tfor i := 0; i < size; i++ {\n\t\t\tfor !index.Empty() && num[i] >= num[index.Last().(int)] {\n\t\t\t\tindex.Pop()\n\t\t\t}\n\t\t\tindex.Append(i)\n\t\t}\n\t\tfor i := size; i < len(num); i++ {\n\t\t\tmaxInWindow.Append(num[index.First().(int)])\n\t\t\tfor !index.Empty() && num[i] >= num[index.Last().(int)] {\n\t\t\t\tindex.Pop()\n\t\t\t}\n\t\t\tif !index.Empty() && index.First().(int) <= i-size {\n\t\t\t\tindex.Shift()\n\t\t\t}\n\t\t\tindex.Append(i)\n\t\t}\n\t\tmaxInWindow.Append(num[index.First().(int)])\n\t}\n\tvar ans []int\n\tfor !maxInWindow.Empty() {\n\t\tans = append(ans, maxInWindow.Shift().(int))\n\t}\n\treturn ans\n}\n"
  },
  {
    "path": "algorithm/sfo/59/ac59_test.go",
    "content": "package problem59\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_maxInWindows(t *testing.T) {\n\tdata := []int{2, 3, 4, 2, 6, 2, 5, 1}\n\tsize := 3\n\n\tfmt.Println(maxInWindows(data, size))\n}\n"
  },
  {
    "path": "algorithm/sfo/61/ac60.go",
    "content": "package problem61\n\nimport \"sort\"\n\nfunc isContinuous(numbers []int) bool {\n\tif nil == numbers || len(numbers) < 5 {\n\t\treturn false\n\t}\n\n\tsort.Ints(numbers)\n\tnumberOfZero, numberOfGap := 0, 0\n\tfor _, value := range numbers {\n\t\tif value == 0 {\n\t\t\tnumberOfZero++\n\t\t}\n\t}\n\n\tsmall, big := 0, 1\n\tfor big < len(numbers) {\n\t\tif numbers[small] == numbers[big] {\n\t\t\treturn false\n\t\t}\n\t\tnumberOfGap += numbers[big] - numbers[small] - 1\n\t\tsmall = big\n\t\tbig++\n\t}\n\tif numberOfGap > numberOfZero {\n\t\treturn false\n\t}\n\treturn true\n}\n"
  },
  {
    "path": "algorithm/sfo/61/ac60_test.go",
    "content": "package problem61\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_isContinuous(t *testing.T) {\n\tdata := []int{3, 4, 0, 5, 1}\n\tfmt.Println(isContinuous(data))\n}\n"
  },
  {
    "path": "algorithm/sfo/62/ac62.go",
    "content": "package problem62\n\nfunc lastRemaining(n, m int) int {\n\tif n < 1 || m < 1 {\n\t\treturn -1\n\t}\n\n\tlast := 0\n\tfor i := 2; i <= n; i++ {\n\t\tlast = (last + m) % i\n\t}\n\treturn last\n}\n"
  },
  {
    "path": "algorithm/sfo/62/ac62_test.go",
    "content": "package problem62\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_lastRemaining(t *testing.T) {\n\tn, m := 5, 3\n\tfmt.Println(lastRemaining(n, m))\n}\n"
  },
  {
    "path": "algorithm/sfo/63/ac63.go",
    "content": "package problem63\n\nfunc maxDiff(numbers []int) int {\n\tif nil == numbers || len(numbers) < 2 {\n\t\treturn -1\n\t}\n\n\tmin := numbers[0]\n\tmax := numbers[1] - min\n\tfor i := 2; i < len(numbers); i++ {\n\t\tif numbers[i-1] < min {\n\t\t\tmin = numbers[i-1]\n\t\t}\n\n\t\tcurrentDiff := numbers[i] - min\n\t\tif currentDiff > max {\n\t\t\tmax = currentDiff\n\t\t}\n\t}\n\treturn max\n}\n"
  },
  {
    "path": "algorithm/sfo/63/ac63_test.go",
    "content": "package problem63\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc Test_maxDiff(t *testing.T) {\n\tdata := []int{9, 11, 8, 5, 7, 12, 16, 14}\n\tfmt.Println(maxDiff(data))\n}\n"
  },
  {
    "path": "algorithm/sfo/65/ac64.go",
    "content": "package problem65\n\nfunc Add(num1, num2 int) int {\n\tvar sum, carry int\n\tfor {\n\t\tsum = num1 ^ num2\n\t\tcarry = (num1 & num2) << 1\n\t\tnum1 = sum\n\t\tnum2 = carry\n\n\t\tif 0 == num2 {\n\t\t\tbreak\n\t\t}\n\t}\n\treturn num1\n}\n"
  },
  {
    "path": "algorithm/sfo/65/ac64_test.go",
    "content": "package problem65\n\nimport (\n\t\"testing\"\n\t\"fmt\"\n)\n\nfunc TestAdd(t *testing.T) {\n\tfmt.Println(Add(9, 11))\n}\n"
  },
  {
    "path": "lib/BinaryTreeNode.go",
    "content": "package lib\n\ntype BinaryTreeNode struct {\n\tvalue       int\n\tleft, right *BinaryTreeNode\n}\n"
  },
  {
    "path": "lib/GetLine.go",
    "content": "package lib\n\nimport (\n\t\"bufio\"\n\t\"strings\"\n\t\"os\"\n)\n\nfunc GetLine() string {\n\treader := bufio.NewReader(os.Stdin)\n\tline, _ := reader.ReadString('\\n')\n\treturn strings.TrimSpace(line)\n}\n"
  },
  {
    "path": "lib/Reverse.go",
    "content": "package lib\n\nfunc Reverse(data []interface{}) {\n\tfor i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {\n\t\tdata[i], data[j] = data[j], data[i]\n\t}\n}\n"
  },
  {
    "path": "lib/grpool/Pool.go",
    "content": "package grpool\n\nimport (\n\t\"sync\"\n)\n\ntype Pool struct {\n\tqueue chan int\n\twg    *sync.WaitGroup\n}\n\nfunc New(size int) *Pool {\n\tif size <= 0 {\n\t\tsize = 1\n\t}\n\treturn &Pool{\n\t\tqueue: make(chan int, size),\n\t\twg:    &sync.WaitGroup{},\n\t}\n}\n\nfunc (p *Pool) Add(delta int) {\n\tfor i := 0; i < delta; i++ {\n\t\tp.queue <- 1\n\t}\n\tfor i := 0; i > delta; i-- {\n\t\t<-p.queue\n\t}\n\tp.wg.Add(delta)\n}\n\nfunc (p *Pool) Done() {\n\t<-p.queue\n\tp.wg.Done()\n}\n\nfunc (p *Pool) WaitAll() {\n\tp.wg.Wait()\n}\n"
  },
  {
    "path": "notes/defer/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n)\n\n// defer 语句会将函数推迟到外层函数返回之后执行。\n// 推迟调用的函数其参数会立即求值，但直到外层函数返回前该函数都不会被调用。\n// 推迟的函数调用会被压入一个栈中，当外层函数返回时，被推迟的函数会按照后进先出的顺序调用。\nfunc main() {\n\tfmt.Println(\"counting\")\n\n\tfor i := 0; i < 10; i++ {\n\t\tdefer fmt.Println(i)\n\t}\n\n\tfmt.Println(\"done.\")\n}\n"
  },
  {
    "path": "notes/learn/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\t\"errors\"\n)\n\nfunc main() {\n\tc1 := make(chan string)\n\tc2 := make(chan string)\n\n\tgo func() {\n\t\ttime.Sleep(time.Second * 1)\n\t\tc1 <- \"one\"\n\t}()\n\tgo func() {\n\t\ttime.Sleep(time.Second * 2)\n\t\tc2 <- \"two\"\n\t}()\n\n\tfor i := 0; i < 2; i++ {\n\t\tselect {\n\t\tcase msg1 := <-c1:\n\t\t\tfmt.Println(\"received\", msg1)\n\t\tcase msg2 := <-c2:\n\t\t\tfmt.Println(\"received\", msg2)\n\t\t}\n\t}\n}\n\nfunc f2(text string) {\n\tfor i := 0; i < 5; i++ {\n\t\tfmt.Println(text, \":\", i)\n\t\ttime.Sleep(1 * time.Second)\n\t}\n}\n\nfunc f1(arg int) (int, error) {\n\tif 42 == arg {\n\t\treturn -1, errors.New(\"can't work with 42\")\n\t}\n\n\treturn arg + 3, nil\n}\n\nfunc modify(slice []int) {\n\tfmt.Printf(\"%p\\n\", &slice)\n\tslice[1] = 10\n}\n\nfunc test(a, b int, c float64) {\n\tfmt.Println(a + b + int(c))\n}\n\nfunc testMap() {\n\tm := make(map[string]int)\n\tm[\"a\"] = 90\n\tm[\"b\"] = 60\n\tfmt.Println(m)\n\tfmt.Println(len(m))\n\n\tvalue, status := m[\"a\"]\n\tfmt.Println(value, status)\n\n\tvalue, status = m[\"aa\"]\n\tfmt.Println(value, status)\n}\n\nfunc testArray() {\n\t//var a [5]int\n\t//fmt.Println(a[3])\n\t//fmt.Println(len(a))\n\t//fmt.Println(cap(a))\n\n\tb := [5]int{0, 1, 2, 3, 4}\n\tfmt.Println(len(b))\n\n\ts := make([]string, 5)\n\tfmt.Println(\"emp:\", s)\n}\n\nfunc IsEven(number int) bool {\n\tif number&1 == 0 {\n\t\treturn true\n\t} else {\n\t\treturn false\n\t}\n}\n\nfunc IsEven2(number int) bool {\n\tif number%2 == 0 {\n\t\treturn true\n\t} else {\n\t\treturn false\n\t}\n}\n\nfunc testEven() {\n\tLOOP := 100000\n\tnum := 9\n\n\tstart1 := time.Now()\n\tfmt.Println(start1)\n\tfor i := 0; i < LOOP; i++ {\n\t\tIsEven(num)\n\t}\n\tend1 := time.Now()\n\tfmt.Println(end1)\n\tfmt.Println(\"位运算：\", end1.Sub(start1))\n\n\tstart2 := time.Now()\n\tfmt.Println(start2)\n\tfor i := 0; i < LOOP; i++ {\n\t\tIsEven2(num)\n\t}\n\tend2 := time.Now()\n\tfmt.Println(end2)\n\tfmt.Println(\"求余运算：\", end2.Sub(start2))\n}\n"
  },
  {
    "path": "notes/main/main.go",
    "content": "package main\n\nimport (\n\t\"GoNotes/src/lib\"\n)\n\nfunc main()  {\n\tlib.SayHello()\n}\n"
  },
  {
    "path": "notes/nil/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\t// nil 是不能比较的， == 对于 nil 来说是一种未定义的操作。\n\t// 运行下面这行将报错: invalid operation: nil == nil (operator == not defined on nil)\n\t// fmt.Println(nil == nil)\n\n\t// nil没有type\n\tfmt.Printf(\"%T\\n\", nil)\n\tfmt.Println(\"**************************\")\n\n\t// 不同类型 nil 的 address 是一样的\n\tvar number *int\n\tvar dict map[string]int\n\tfmt.Printf(\"%p\\n\", number)\n\tfmt.Printf(\"%p\\n\", dict)\n\tfmt.Println(\"**************************\")\n\n\t// nil 是 map，slice，pointer，channel，func，interface 的零值\n\tvar m map[int]string\n\tvar ptr *int\n\tvar c chan int\n\tvar sl []int\n\tvar f func()\n\tvar i interface{}\n\tfmt.Printf(\"%#v\\n\", m)\n\tfmt.Printf(\"%#v\\n\", ptr)\n\tfmt.Printf(\"%#v\\n\", c)\n\tfmt.Printf(\"%#v\\n\", sl)\n\tfmt.Printf(\"%#v\\n\", f)\n\tfmt.Printf(\"%#v\\n\", i)\n\tfmt.Println(\"**************************\")\n\n}\n"
  },
  {
    "path": "notes/switch/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"runtime\"\n\t\"time\"\n)\n\n// switch 的 case 语句从上到下顺序执行，直到匹配成功时停止。\n// switch 只运行选定的 case, 除非以 fallthrough 结束，否则分支自动终止。\n// switch 的 case 无需为常数，且取值不必为整数。\nfunc main() {\n\tfmt.Print(\"Go runs on \")\n\tswitch os := runtime.GOOS; os {\n\tcase \"darwin\":\n\t\tfmt.Println(\"OS X.\")\n\tcase \"linux\":\n\t\tfmt.Println(\"Linux\")\n\tdefault:\n\t\tfmt.Printf(\"%s.\", os)\n\t}\n\n\ttest(3.1415926)\n\ttest(1)\n\ttest(1.0)\n\ttest(2.71828)\n\n\ttest2()\n\n\n\n\n}\n\nfunc test(x float64) {\n\tswitch x {\n\tcase 3.1415926:\n\t\tfmt.Println(\"PI\")\n\tcase 1.0:\n\t\tfmt.Println(\"1 or 1.0\")\n\tdefault:\n\t\tfmt.Println(\"no match\", x)\n\t}\n}\n\n// 没有条件的 switch 同 switch true 一样。这种形式能将一长串 if-then-else 写得更加清晰。\nfunc test2() {\n\tt := time.Now()\n\tswitch {\n\tcase t.Hour() < 12:\n\t\tfmt.Println(\"Good morning.\")\n\tcase t.Hour() < 17:\n\t\tfmt.Println(\"Good afternoon.\")\n\tdefault:\n\t\tfmt.Println(\"Good evening.\")\n\t}\n}\n"
  },
  {
    "path": "notes/time/main.go",
    "content": "package main\n\nimport (\n\t\"time\"\n\t\"fmt\"\n)\n\nfunc main()  {\n\tfmt.Println(\"现在时间是: \", time.Now())\n\n\tt := time.Now()\n\tfmt.Println(t.Year())\n\tfmt.Println(t.Month())\n\tfmt.Println(t.Day())\n\tfmt.Println(t.Hour())\n\tfmt.Println(t.Minute())\n\tfmt.Println(t.Second())\n\tfmt.Println(t.Date())\n\tfmt.Println(t.Clock())\n\n\tfmt.Println(t.Format(\"19:21:01.123\"))\n}\n"
  },
  {
    "path": "notes/函数/main.go",
    "content": "package main\n\nimport \"fmt\"\n\n// 函数可以接受0个或多个参数\nfunc main() {\n\tfmt.Println(\"this is main function\")\n\tfmt.Println(Add(9, 12))\n\tfmt.Println(add(9, 12, 1))\n\tfmt.Println(add2(9, 12, 1))\n\tfmt.Println(add3(false, 12, 1))\n\tfmt.Println(swap(\"time\", \"golang\"))\n\tfmt.Println(split(20))\n}\n\nfunc Add(x int, y int) int {\n\treturn x + y\n}\n\nfunc add(x int, y int, z int) int {\n\treturn x + y + z\n}\n\nfunc add2(x, y, z int) int {\n\treturn x + y + z\n}\n\nfunc add3(x bool, y, z int) (bool, int) {\n\treturn x, y + z\n}\n\nfunc swap(x, y string) (string, string) {\n\ta, b := x, y\n\tfmt.Print(\"swap->\", a, \" \",b, \"->\")\n\treturn y, x\n}\n\n// 命名返回值\n// Go 的返回值可以被命名，它们会被视作定义在函数顶部的变量。\n// 没有参数的 return 语句返回已命名的返回值，也就是 “直接” 返回。\nfunc split(sum int) (x, y int)  {\n\tx = sum * 2 - 1\n\ty = x - sum\n\treturn\n}\n"
  },
  {
    "path": "notes/判断/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n)\n\nfunc main() {\n\tfmt.Println(myPow(2, 3, 99))\n\tfmt.Println(myPow(2, 3, 5))\n\tfmt.Printf(\"sqrt %v is %v\", 2, Sqrt(2))\n}\n\n// if 语句可以在表达式前执行一个简单的语句，该语句声明的变量作用域仅在 if 之内。\n// 在 if 的简短语句中声明的变量同样可以在任何对应的 else 块中使用。\nfunc myPow(x, y, ans float64) float64 {\n\tif z := math.Pow(x, y); z < ans {\n\t\treturn z\n\t} else {\n\t\tfmt.Printf(\"z type: %T\\n\", z)\n\t}\n\treturn ans\n}\n\n// 牛顿法实现平方根函数\nfunc Sqrt(x float64) float64 {\n\tif 0 >= x {\n\t\treturn 0\n\t}\n\n\tz := 1.0\n\tfor {\n\t\ttemp := z - (z*z-x)/(2*z)\n\t\tif math.Abs(temp-z) < 1e-12 {\n\t\t\tbreak\n\t\t}\n\t\tz = temp\n\t}\n\treturn z\n}\n"
  },
  {
    "path": "notes/协程/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\t\"runtime\"\n\t\"github.com/mayuanucas/mygo/lib/grpool\"\n)\n\nfunc main() {\n\t//runtime.GOMAXPROCS(1)\n\t//\n\t//var wg sync.WaitGroup\n\t//wg.Add(2)\n\t//\n\t//fmt.Println(\"Start Goroutines\")\n\t//go func() {\n\t//\tdefer wg.Done()\n\t//\n\t//\tfor i := 0; i < 3; i++ {\n\t//\t\tfor char := 'a'; char < 'a'+26; char ++ {\n\t//\t\t\tfmt.Printf(\"%c \", char)\n\t//\t\t}\n\t//\t}\n\t//}()\n\t//\n\t//go func() {\n\t//\tdefer wg.Done()\n\t//\n\t//\tfor i := 0; i < 3; i++ {\n\t//\t\tfor char := 'A'; char < 'A'+26; char ++ {\n\t//\t\t\tfmt.Printf(\"%c \", char)\n\t//\t\t}\n\t//\t}\n\t//}()\n\t//\n\t//fmt.Println(\"Waiting To Finish\")\n\t//\n\t//wg.Wait()\n\t//fmt.Println(\"\\nTerminating Program\")\n\n\tpool := grpool.New(runtime.NumCPU() + 1)\n\tfor i := 1; i <= 5; i++ {\n\t\tpool.Add(2)\n\n\t\tgo lowwerCase(i, pool)\n\t\tgo upperCase(i, pool)\n\t}\n\tpool.WaitAll()\n\n\tfmt.Println(\"all done.\")\n}\n\nfunc lowwerCase(id int, group *grpool.Pool) {\n\tdefer group.Done()\n\n\tfmt.Println(\"lowwerCase ID-->\", id)\n\tfor char := 'a'; char <= 'z'; char += 1 {\n\t\tfmt.Printf(\"%c \", char)\n\t\ttime.Sleep(100 * time.Millisecond)\n\t}\n\tfmt.Println()\n\tfmt.Println(\"done-->\", id)\n}\n\nfunc upperCase(id int, group *grpool.Pool) {\n\tdefer group.Done()\n\n\tfmt.Println(\"upperCase ID-->\", id)\n\tfor char := 'A'; char <= 'Z'; char += 1 {\n\t\tfmt.Printf(\"%c \", char)\n\t\ttime.Sleep(500 * time.Millisecond)\n\t}\n\tfmt.Println()\n\tfmt.Println(\"done-->\", id)\n}\n"
  },
  {
    "path": "notes/变量/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n)\n\nfunc main() {\n\t// 基本类型\n\tvar (\n\t\ta bool\n\t\tb string\n\t\tc byte\n\t\td int\n\t\te rune\n\t\tf float64\n\t\tg complex64\n\t)\n\n\tfmt.Printf(\"%v %q %v %v %v %v %v\", a, b, c, d, e, f, g)\n\n\t// 变量初始化，变量声明可以包含初始化值。如果初始化值已存在，可以省略类型，变量从初始值获得类型。\n\tvar i, j, k = 12.99, true, \"test\"\n\tfmt.Println(i, j, k)\n\tfmt.Printf(\"i: %T, j:%T, k: %T\\n\", i, j, k)\n\n\t// 在函数中,简洁赋值语句 := 可在类型明确的地方代替 var 声明。\n\t// 函数外的每个语句都必须以关键字开始（var, func 等等），因此 := 结构不能在函数外使用。\n\tm := 3\n\tn := false\n\tstr2 := \"golang\"\n\tfmt.Println(m, n, str2)\n\n\t// 类型转换\n\tvar x, y = 3, 4\n\tvar ans = math.Sqrt(float64(x*x + y*y))\n\tfmt.Printf(\"ans: %v, type: %T\\n\", ans, ans)\n\n}\n"
  },
  {
    "path": "notes/命令行参数/iie.go",
    "content": "package 命令行参数\n\nimport (\n\t\"flag\"\n\t\"fmt\"\n\t\"runtime\"\n)\n\nfunc usage() {\n\tfmt.Printf(\"iie 是一个工具-> %s %s\\n\", runtime.GOOS, runtime.GOARCH)\n\tinputDir := flag.String(\"i\", \"\", \"源文件夹路径\")\n\toutputDir := flag.String(\"o\", \"./\", \"保存路径\")\n\tflag.Parse()\n\n\tif \"\" != *inputDir {\n\t\tfmt.Println(\"输入路径:\", *inputDir)\n\t\tfmt.Println(\"输出路径:\", *outputDir)\n\t} else {\n\t\tfmt.Println(\"参数无效\")\n\t}\n}\n\nfunc main() {\n\tusage()\n}\n"
  },
  {
    "path": "notes/导入导出/main.go",
    "content": "package main\n\n// import \"fmt\"\n// import \"math\nimport (\n\t\"fmt\"\n\tm \"math\" // 起别名\n\t. \"time\" // 直接使用该包\n)\n\nfunc main() {\n\tfmt.Printf(\"Sqrt %v is %v\\n\", 3, m.Sqrt(3))\n\tfmt.Println(\"time is \", Now())\n\tfmt.Println(\"PI: \", m.Pi)\n}\n\n// 导出\n// 在 Go 中，如果一个名字以大写字母开头，那么它就是导出的。例如： Pi 就是导出的，它导出自 math 包。\n// 在导入一个包时，只能引用其中已导出的名字。任何“未导出”的名字在该包外均无法访问。\n"
  },
  {
    "path": "notes/常量/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n)\n\n// 常量可以是字符、字符串、布尔值或数值\n// 常量不能用 := 语法声明\nconst PI = 3.1415926\n\nfunc main(){\n\tfmt.Printf(\"PI: %v, %T\\n\", PI, PI)\n\n\tconst (\n\t\tTRUE = true\n\t\tFALSE = false\n\t)\n\tfmt.Println(TRUE, FALSE)\n\n}"
  },
  {
    "path": "notes/循环/main.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tsum := 0\n\tfor i := 0; i < 10; i++ {\n\t\tsum += i\n\t}\n\tfmt.Println(sum)\n\n\tsum = 1\n\tfor ; sum < 100; {\n\t\tsum += sum\n\t}\n\tfmt.Println(sum)\n\n\t// for 是 Go 中的 “while”\n\t// 此时可以去掉分号，因为 C 的 while 在 Go 中叫 for\n\tsum = 1\n\tfor sum < 100 {\n\t\tsum += sum\n\t}\n\tfmt.Println(sum)\n\n\t// 省略循环条件，该循环就不会结束，因此无限循环可以写得很紧凑\n\t// for {\n\t//\n\t// }\n\n}\n"
  },
  {
    "path": "notes/数组/main.go",
    "content": "package main\n\nimport \"fmt\"\n\ntype Currency int\n\nconst (\n\n\tUSD Currency = iota // 美元\n\n\tEUR\n\n\t// 欤元\n\n\tGBP\n\n\t// 英镑\n\n\tRMB\n\n\t// 人民币\n\n)\n\nfunc main() {\n\tsymbol := [...]string{USD: \"$\", EUR: \"€\", GBP: \" ￡\", RMB: \"￥\" }\n\n\tfmt.Println(RMB, symbol[RMB]) // \"3 ￥\"\n}\n\n"
  },
  {
    "path": "notes/输入/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"bufio\"\n\t\"os\"\n\t\"strings\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tfmt.Println(\"请输入内容:\")\n\n\treader := bufio.NewReader(os.Stdin)\n\tinput, _ := reader.ReadString('\\n')\n\ttext := strings.TrimSpace(input)\n\n\tfmt.Println(\"输入是:\", text)\n\n\tfmt.Println(\"请输入数字:\")\n\tinput, _ = reader.ReadString('\\n')\n\tnumber, _ := strconv.Atoi(strings.TrimSpace(input))\n\tfmt.Printf(\"%v,%T\\n\", number, number)\n\n\tfmt.Println(\"请输入多个数字:\")\n\tinput, _ = reader.ReadString('\\n')\n\ttemp := strings.TrimSpace(input)\n\tstrs := strings.Split(temp, \" \")\n\tfmt.Println(strs)\n}\n"
  },
  {
    "path": "notes/输出/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n)\n\n/*\n格式化输出语法\n\n%d\t\t\t十进制整数\n%x %o %b\t十六进制、八进制、二进制整数\n%f %g %e\t浮点数: 3.1415 3.141592653589793 3.141593e+00\n%t\t\t\t布尔: true 或 false\n%c\t\t\t字符（rune）(Unicode码点)\n%s\t\t\t字符串\n%q\t\t\t带双引号的字符串 \"abc\" 或带单引号的字符 'c'\n%v\t\t\t变量的自然形式\n%T\t\t\t变量的类型\n%%\t\t\t字面上的百分号标志（无操作数）\n */\n\n /*\n General\n\n \t%v 以默认方式打印变量的值\n    %T 打印变量的类型\n\nInteger\n\n    %+d 带符号的整型，fmt.Printf(\"%+d\", -255)输出-255\n    %q 打印单引号\n    %o 不带零的八进制\n    %#o 带零的八进制\n    %x 小写的十六进制\n    %X 大写的十六进制\n    %#x 带0x的十六进制\n    %U 打印Unicode字符\n    %#U 打印带字符的Unicode\n    %b 打印整型的二进制\n\nInteger width\n\n    %5d 表示该整型最大长度是5，下面这段代码\n\n      fmt.Printf(\"|%5d|\", 1)\n      fmt.Printf(\"|%5d|\", 1234567)\n\n输出结果如下：\n\n|    1|\n|1234567|\n\n    %-5d则相反，打印结果会自动左对齐\n    %05d会在数字前面补零。\n\nFloat\n\n    %f (=%.6f) 6位小数点\n    %e (=%.6e) 6位小数点（科学计数法）\n    %g 用最少的数字来表示\n    %.3g 最多3位数字来表示\n    %.3f 最多3位小数来表示\n\nString\n\n    %s 正常输出字符串\n    %q 字符串带双引号，字符串中的引号带转义符\n    %#q 字符串带反引号，如果字符串内有反引号，就用双引号代替\n    %x 将字符串转换为小写的16进制格式\n    %X 将字符串转换为大写的16进制格式\n    % x 带空格的16进制格式\n\nString Width (以5做例子）\n\n    %5s 最小宽度为5\n    %-5s 最小宽度为5（左对齐）\n    %.5s 最大宽度为5\n    %5.7s 最小宽度为5，最大宽度为7\n    %-5.7s 最小宽度为5，最大宽度为7（左对齐）\n    %5.3s 如果宽度大于3，则截断\n    %05s 如果宽度小于5，就会在字符串前面补零\n\nStruct\n\n    %v 正常打印。比如：{sam {12345 67890}}\n    %+v 带字段名称。比如：{name:sam phone:{mobile:12345 office:67890}\n    %#v 用Go的语法打印。\n    比如main.People{name:”sam”, phone:main.Phone{mobile:”12345”, office:”67890”}}\n\nBoolean\n\n    %t 打印true或false\n\nPointer\n\n    %p 带0x的指针\n    %#p 不带0x的指针\n\n  */\nfunc main() {\n\tlearnScan()\n}\n\nfunc learnScan(){\n\tfmt.Println(\"请输入内容:\")\n\n\tvar n int\n\tfmt.Scanln(&n)\n\n\tnumbers := make([]int, n)\n\tfor i:=0; i<n; i++ {\n\t\tfmt.Scan(&numbers[i])\n\t}\n\n\tfmt.Println(n)\n\tfmt.Println(numbers)\n}\n\nfunc learnPrintf(){\n\tfmt.Printf(\"%05d\\n\", 1)\n\tfmt.Printf(\"|%5d|\\n\", 1234567)\n\tfmt.Printf(\"%-5d\\n\", 1)\n\tfmt.Printf(\"%+d\\n\", -3)\n\tfmt.Printf(\"二进制: %b\\n\", 3)\n\tfmt.Printf(\"八进制: %#o\\n\", 3)\n\tfmt.Printf(\"十六进制: %#x\\n\", 15)\n\tfmt.Printf(\"%f\\n\", 3.141592653589793)\n\tfmt.Printf(\"%g\\n\", 3.141592653589793)\n\tfmt.Printf(\"%.2e\\n\", 3.141592653589793)\n\tfmt.Printf(\"%s\\n\", \"test\\\"\")\n\tfmt.Printf(\"%q\\n\", \"test\\\"\")\n\tfmt.Printf(\"%#q\\n\", \"test\\\"\")\n\tfmt.Printf(\"%t\\n\", true)\n\tfmt.Printf(\"%v\\n\", false)\n}\n"
  }
]