{"id":53588,"date":"2024-12-03T09:23:36","date_gmt":"2024-12-03T01:23:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53588\/"},"modified":"2024-12-03T09:23:36","modified_gmt":"2024-12-03T01:23:36","slug":"%e5%90%8e%e8%bf%9b%e5%85%88%e5%87%ba%e8%bf%98%e6%98%af%e5%85%88%e8%bf%9b%e5%85%88%e5%87%ba%ef%bc%9f%e5%a0%86%e6%a0%88-%e9%98%9f%e5%88%97%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53588\/","title":{"rendered":"\u540e\u8fdb\u5148\u51fa\u8fd8\u662f\u5148\u8fdb\u5148\u51fa\uff1f\u5806\u6808\/\u961f\u5217\u6307\u5357"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u540e\u8fdb\u5148\u51fa\u8fd8\u662f\u5148\u8fdb\u5148\u51fa\uff1f\u5806\u6808\/\u961f\u5217\u6307\u5357<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p><span style=\"font-size: 15px\">\u5b66\u4e60\u77e5\u8bc6\u8981\u5584\u4e8e\u601d\u8003\uff0c\u601d\u8003\uff0c\u518d\u601d\u8003\uff01\u4eca\u5929\u7c73\u4e91\u5c0f\u7f16\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u540e\u8fdb\u5148\u51fa\u8fd8\u662f\u5148\u8fdb\u5148\u51fa\uff1f\u5806\u6808\/\u961f\u5217\u6307\u5357\u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u5305\u542b<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60\u6216\u51c6\u5907\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u5c31\u90fd\u4e0d\u8981\u9519\u8fc7\u672c\u6587\u5566~\u8ba9\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff0c\u80fd\u5e2e\u52a9\u5230\u4f60\u5c31\u66f4\u597d\u4e86\uff01<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241202\/1733121016674d53f8f3fa6.jpg\" class=\"aligncenter\" title=\"\u540e\u8fdb\u5148\u51fa\u8fd8\u662f\u5148\u8fdb\u5148\u51fa\uff1f\u5806\u6808\/\u961f\u5217\u6307\u5357\u63d2\u56fe\" alt=\"\u540e\u8fdb\u5148\u51fa\u8fd8\u662f\u5148\u8fdb\u5148\u51fa\uff1f\u5806\u6808\/\u961f\u5217\u6307\u5357\u63d2\u56fe\" \/><\/p>\n<blockquote>\n<p><em>\u5047\u8bbe\u7406\u89e3 big o \u8868\u793a\u6cd5\u3002 javascript \u4e2d\u6709\u793a\u4f8b\u3002\u8d44\u6599\u53c2\u8003 gayle laakmann mcdowell \u7684\u300acracking the coding interview\u300b<\/em><\/p>\n<\/blockquote>\n<p>\u4eca\u5929\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u4e24\u79cd\u57fa\u672c\u7684\u6570\u636e\u7ed3\u6784\uff1a<strong>\u5806\u6808<\/strong>\u548c<strong>\u961f\u5217<\/strong>\u3002\u6211\u4eec\u5c06\u6df1\u5165\u7814\u7a76\u5b83\u4eec\u7684\u6982\u5ff5\u3001\u7528\u4f8b\uff0c\u5e76\u4f7f\u7528\u7ecf\u5178\u548c\u57fa\u4e8e\u539f\u578b\u7684\u65b9\u6cd5\u5728 javascript \u4e2d\u5b9e\u73b0\u5b83\u4eec\u3002<\/p>\n<hr>\n<h2> \u5806\u6808\uff1a\u540e\u8fdb\u5148\u51fa (lifo) <\/h2>\n<p>\u60f3\u8c61\u4e00\u4e0b\u4e00\u5806\u714e\u997c\u2014\u2014\u4f60\u6700\u540e\u653e\u5728\u4e0a\u9762\u7684\u4e00\u4e2a\u662f\u4f60\u7b2c\u4e00\u4e2a\u5403\u7684\u3002\u8fd9\u6b63\u662f\u5806\u6808\u6570\u636e\u7ed3\u6784\u7684\u5de5\u4f5c\u539f\u7406\u3002\u5b83\u9075\u5faa<strong>\u540e\u8fdb\u5148\u51fa\uff08lifo\uff09\u539f\u5219<\/strong>.<\/p>\n<h3> \u5173\u952e\u64cd\u4f5c <\/h3>\n<ul>\n<li> push(item): \u5c06\u4e00\u4e2a\u9879\u76ee\u6dfb\u52a0\u5230\u5806\u6808\u9876\u90e8<\/li>\n<li> pop()\uff1a\u4ece\u5806\u6808\u4e2d\u5220\u9664\u9876\u90e8\u9879\u76ee<\/li>\n<li> peek()\uff1a\u8fd4\u56de\u9876\u90e8\u9879\u76ee\u800c\u4e0d\u5220\u9664\u5b83<\/li>\n<li> isempty()\uff1a\u68c0\u67e5\u6808\u662f\u5426\u4e3a\u7a7a<\/li>\n<\/ul>\n<h3> \u4f7f\u7528\u6848\u4f8b <\/h3>\n<p>\u5806\u6808\u5728\u6d89\u53ca\u4ee5\u4e0b\u573a\u666f\u65f6\u7279\u522b\u6709\u7528\uff1a<\/p>\n<ul>\n<li>\u9012\u5f52\u7b97\u6cd5<\/li>\n<li>\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u7684\u64a4\u6d88\u673a\u5236<\/li>\n<\/ul>\n<h3> javascript \u5b9e\u73b0 <\/h3>\n<h4> \u7ecf\u5178\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b <\/h4>\n<pre>class stack {\n  constructor() {\n    this.items = [];\n  }\n\n  push(element) {\n    this.items.push(element);\n  }\n\n  pop() {\n    if (this.isempty()) {\n      return \"stack is empty\";\n    }\n    return this.items.pop();\n  }\n\n  peek() {\n    if (this.isempty()) {\n      return \"stack is empty\";\n    }\n    return this.items[this.items.length - 1];\n  }\n\n  isempty() {\n    return this.items.length === 0;\n  }\n\n  size() {\n    return this.items.length;\n  }\n\n  clear() {\n    this.items = [];\n  }\n}\n<\/pre>\n<h4> \u57fa\u4e8e\u539f\u578b <\/h4>\n<pre>function stack() {\n  this.items = [];\n}\n\nstack.prototype.push = function(element) {\n  this.items.push(element);\n};\n\nstack.prototype.pop = function() {\n  if (this.isempty()) {\n    return \"stack is empty\";\n  }\n  return this.items.pop();\n};\n\nstack.prototype.peek = function() {\n  if (this.isempty()) {\n    return \"stack is empty\";\n  }\n  return this.items[this.items.length - 1];\n};\n\nstack.prototype.isempty = function() {\n  return this.items.length === 0;\n};\n\nstack.prototype.size = function() {\n  return this.items.length;\n};\n\nstack.prototype.clear = function() {\n  this.items = [];\n};\n<\/pre>\n<hr>\n<h2> \u961f\u5217\uff1a\u5148\u8fdb\u5148\u51fa (fifo) <\/h2>\n<p>\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u5c06\u6ce8\u610f\u529b\u8f6c\u79fb\u5230\u961f\u5217\u4e0a\u3002\u4e0e\u5806\u6808\u4e0d\u540c\uff0c\u961f\u5217\u9075\u5faa<strong>\u5148\u8fdb\u5148\u51fa\uff08fifo\uff09\u539f\u5219<\/strong>\u3002\u60f3\u8c61\u4e00\u4e0b\u97f3\u4e50\u4f1a\u573a\u5730\u7684\u6392\u961f\u2014\u2014\u7b2c\u4e00\u4e2a\u5230\u8fbe\u7684\u4eba\u5c31\u662f\u7b2c\u4e00\u4e2a\u8fdb\u5165\u7684\u4eba\u3002<\/p>\n<h3> \u5173\u952e\u64cd\u4f5c <\/h3>\n<ul>\n<li> enqueue(item): \u5c06\u4e00\u4e2a\u9879\u76ee\u6dfb\u52a0\u5230\u961f\u5217\u672b\u5c3e<\/li>\n<li> dequeue()\uff1a\u4ece\u961f\u5217\u4e2d\u5220\u9664\u7b2c\u4e00\u4e2a\u9879\u76ee<\/li>\n<li> peek()\uff1a\u8fd4\u56de\u7b2c\u4e00\u9879\u800c\u4e0d\u5220\u9664\u5b83<\/li>\n<li> isempty()\uff1a\u68c0\u67e5\u961f\u5217\u662f\u5426\u4e3a\u7a7a<\/li>\n<\/ul>\n<h3> \u4f7f\u7528\u6848\u4f8b <\/h3>\n<p>\u961f\u5217\u5e38\u7528\u4e8e\uff1a<\/p>\n<ul>\n<li>\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\u7b97\u6cd5<\/li>\n<li>\u4efb\u52a1\u8c03\u5ea6<\/li>\n<\/ul>\n<h3> javascript \u5b9e\u73b0 <\/h3>\n<h4> \u7ecf\u5178\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b <\/h4>\n<pre>class node {\n  constructor(data) {\n    this.data = data;\n    this.next = null;\n  }\n}\n\nclass queue {\n  constructor() {\n    this.start = null;\n    this.end = null;\n    this.size = 0;\n  }\n\n  enqueue(element) {\n    const newnode = new node(element);\n    if (this.isempty()) {\n      this.start = newnode;\n      this.end = newnode;\n    } else {\n      this.end.next = newnode;\n      this.end = newnode;\n    }\n    this.size++;\n  }\n\n  dequeue() {\n    if (this.isempty()) {\n      return \"queue is empty\";\n    }\n    const removeddata = this.start.data;\n    this.start = this.start.next;\n    this.size--;\n    if (this.isempty()) {\n      this.end = null;\n    }\n    return removeddata;\n  }\n\n  peek() {\n    if (this.isempty()) {\n      return \"queue is empty\";\n    }\n    return this.start.data;\n  }\n\n  isempty() {\n    return this.size === 0;\n  }\n\n  getsize() {\n    return this.size;\n  }\n\n  clear() {\n    this.start = null;\n    this.end = null;\n    this.size = 0;\n  }\n}\n<\/pre>\n<h4> \u57fa\u4e8e\u539f\u578b <\/h4>\n<pre>function Node(data) {\n  this.data = data;\n  this.next = null;\n}\n\nfunction Queue() {\n  this.start = null;\n  this.end = null;\n  this.size = 0;\n}\n\nQueue.prototype.enqueue = function(element) {\n  const newNode = new Node(element);\n  if (this.isEmpty()) {\n    this.start = newNode;\n    this.end = newNode;\n  } else {\n    this.end.next = newNode;\n    this.end = newNode;\n  }\n  this.size++;\n};\n\nQueue.prototype.dequeue = function() {\n  if (this.isEmpty()) {\n    return \"Queue is empty\";\n  }\n  const removedData = this.start.data;\n  this.start = this.start.next;\n  this.size--;\n  if (this.isEmpty()) {\n    this.end = null;\n  }\n  return removedData;\n};\n\nQueue.prototype.peek = function() {\n  if (this.isEmpty()) {\n    return \"Queue is empty\";\n  }\n  return this.start.data;\n};\n\nQueue.prototype.isEmpty = function() {\n  return this.size === 0;\n};\n\nQueue.prototype.getSize = function() {\n  return this.size;\n};\n\nQueue.prototype.clear = function() {\n  this.start = null;\n  this.end = null;\n  this.size = 0;\n};\n<\/pre>\n<hr>\n<h2> \u7ee9\u6548\u5206\u6790 <\/h2>\n<p>\u5806\u6808\u548c\u961f\u5217\u90fd\u63d0\u4f9b <span><span>     o   (   1   )  o(1)  <span><span style=\"height:1em;vertical-align:-0.25em\">o(1)<\/span><\/span><\/span> <\/span> \u6709\u6548\u5b9e\u73b0\u65f6\uff0c\u5176\u6838\u5fc3\u64cd\u4f5c\uff08\u5806\u6808\u7684\u538b\u5165\/\u5f39\u51fa\u3001\u961f\u5217\u7684\u5165\u961f\/\u51fa\u961f\uff09\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u8fd9\u4f7f\u5f97\u5b83\u4eec\u5728\u7279\u5b9a\u7528\u4f8b\u4e2d\u5177\u6709\u9ad8\u6027\u80fd\u3002<\/p>\n<p>\u5b83\u4eec\u90fd\u4e3a\u8bb8\u591a\u5e38\u89c1\u7684\u7f16\u7a0b\u95ee\u9898\u63d0\u4f9b\u4e86\u4f18\u96c5\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5e76\u6784\u6210\u4e86\u66f4\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u7684\u57fa\u7840\u3002\u901a\u8fc7\u5728 javascript \u4e2d\u7406\u89e3\u548c\u5b9e\u73b0\u8fd9\u4e9b\u7ed3\u6784\uff0c\u60a8\u5c31\u53ef\u4ee5\u5f88\u597d\u5730\u89e3\u51b3\u5404\u79cd leetcode\/\u7b97\u6cd5\u95ee\u9898 ?.<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u540e\u8fdb\u5148\u51fa\u8fd8\u662f\u5148\u8fdb\u5148\u51fa\uff1f\u5806\u6808\/\u961f\u5217\u6307\u5357\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664    <\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u5982\u4f55\u7528MySQL UPDATE\u8bed\u53e5\u548cLEFT JOIN\u66f4\u65b0\u5b66\u751f\u8868\u4e2d\u6bcf\u4e2a\u5b66\u751f\u7684\u6700\u9ad8\u5206\u6570\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u540e\u8fdb\u5148\u51fa\u8fd8\u662f\u5148\u8fdb\u5148\u51fa\uff1f\u5806\u6808\/\u961f\u5217\u6307\u5357 \u6536\u85cf \u5b66\u4e60\u77e5\u8bc6\u8981\u5584\u4e8e\u601d\u8003\uff0c\u601d\u8003\uff0c\u518d\u601d\u8003\uff01\u4eca\u5929\u7c73\u4e91\u5c0f\u7f16\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765\u300a\u540e\u8fdb\u5148\u51fa\u8fd8\u662f\u5148\u8fdb\u5148\u51fa\uff1f\u5806\u6808\/\u961f\u5217\u6307\u5357\u300b\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u5305\u542b\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60\u6216\u51c6\u5907\u5b66\u4e60\u6587\u7ae0\uff0c\u5c31\u90fd\u4e0d\u8981\u9519\u8fc7\u672c\u6587\u5566~\u8ba9\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff0c\u80fd\u5e2e\u52a9\u5230\u4f60\u5c31\u66f4\u597d\u4e86\uff01 \u5047\u8bbe\u7406\u89e3 big o \u8868\u793a\u6cd5\u3002 javascript \u4e2d\u6709\u793a\u4f8b\u3002\u8d44\u6599\u53c2\u8003 gayle laakmann mcdowell \u7684\u300acracking the coding interview\u300b \u4eca\u5929\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u4e24\u79cd\u57fa\u672c\u7684\u6570\u636e\u7ed3\u6784\uff1a\u5806\u6808\u548c\u961f\u5217\u3002\u6211\u4eec\u5c06\u6df1\u5165\u7814\u7a76\u5b83\u4eec\u7684\u6982\u5ff5\u3001\u7528\u4f8b\uff0c\u5e76\u4f7f\u7528\u7ecf\u5178\u548c\u57fa\u4e8e\u539f\u578b\u7684\u65b9\u6cd5\u5728 javascript \u4e2d\u5b9e\u73b0\u5b83\u4eec\u3002 \u5806\u6808\uff1a\u540e\u8fdb\u5148\u51fa (lifo) \u60f3\u8c61\u4e00\u4e0b\u4e00\u5806\u714e\u997c\u2014\u2014\u4f60\u6700\u540e\u653e\u5728\u4e0a\u9762\u7684\u4e00\u4e2a\u662f\u4f60\u7b2c\u4e00\u4e2a\u5403\u7684\u3002\u8fd9\u6b63\u662f\u5806\u6808\u6570\u636e\u7ed3\u6784\u7684\u5de5\u4f5c\u539f\u7406\u3002\u5b83\u9075\u5faa\u540e\u8fdb\u5148\u51fa\uff08lifo\uff09\u539f\u5219. \u5173\u952e\u64cd\u4f5c push(item): \u5c06\u4e00\u4e2a\u9879\u76ee\u6dfb\u52a0\u5230\u5806\u6808\u9876\u90e8 pop()\uff1a\u4ece\u5806\u6808\u4e2d\u5220\u9664\u9876\u90e8\u9879\u76ee peek()\uff1a\u8fd4\u56de\u9876\u90e8\u9879\u76ee\u800c\u4e0d\u5220\u9664\u5b83 isempty()\uff1a\u68c0\u67e5\u6808\u662f\u5426\u4e3a\u7a7a \u4f7f\u7528\u6848\u4f8b \u5806\u6808\u5728\u6d89\u53ca\u4ee5\u4e0b\u573a\u666f\u65f6\u7279\u522b\u6709\u7528\uff1a \u9012\u5f52\u7b97\u6cd5 \u6587\u672c\u7f16\u8f91\u5668\u4e2d\u7684\u64a4\u6d88\u673a\u5236 javascript \u5b9e\u73b0 \u7ecf\u5178\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b class stack { constructor() { this.items = []; } push(element) { this.items.push(element); } pop() { if (this.isempty()) { return &#8220;stack [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-53588","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=53588"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53588\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}