EricccTaiwan
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # info2024-homework2 > 歐麥-Allmine > 哈哈球-Hahaball > R : Interviewer, E : Interviewee | 影片 | Interviewer | Interviewee | | -------- | -------- | -------- | | [影片1](https://www.youtube.com/watch?v=8zD7ZNKfKKo) | 哈哈球 | 歐麥 | | [影片2](https://www.youtube.com/watch?v=EohokVYF_Ug) | 歐麥 | 哈哈球 | ## [20. Valid Parentheses()](https://leetcode.com/problems/valid-parentheses/) R : 您好,我是哈哈球,我們最近有一個改進內部IDE的需求,當開發人員在寫扣時,經常會出現括號不匹配的問題,這不僅可能導致執行錯誤,也會增加代碼調試的負擔。為了改善這一點,我們希望在內部的 IDE 中添加一個即時的括號匹配檢查功能。這個功能要能即時檢查各類括號(如 `()`, `{}`, `[]`)的匹配情況,並在發現不匹配的括號時立刻顯示提示,以協助同仁迅速找到並修正錯誤。 ### (Repeat) E : 所以您的問題是, 我需要實作一個功能, 檢查IDE裡的括號是否有各自正確匹配? R : 對的 ### (Example) E : 兩個左括號`([`, 如果對應到兩個右括號`])`就可以回傳`True` 但如果括號大小不匹配, 例如`{(})`,或是數量不匹配`{}}}}`,則都要回傳`False` R : 對的,僅需考慮括號數量匹配與否, 不用考慮大小括號優先順序問題 ### (Approach) E : 好, 我先寫下方法, 我想用`stack[]`LIFO的特性, 來記錄括號的順序, 遇到左括號就push進`stack`, 遇到右括號則pop, 但要與`stack`最上方的左括號匹配,以及top不能為`-1`,否則就回傳`false` 最後回傳`top==-1` #### psuedo code ``` top = -1 stack[top] 1. *s = '(', stack[++top] = *s; 2. *s = ')', if(top>-1且stack[top]=='(') 跳出switch-case, 否則return false 最後return top==-1. ``` R : 恩,你的做法聽起來沒有太大的問題 ### (code) ```c== bool isValid(char* s) { int len = strlen(s); char stack[len]; int top = -1; while(*s!='\0') { switch(*s) { case ')': if(top>-1 && stack[top--]=='(') break; else return false; case ']': if(top>-1 && stack[top--]=='[') break; else return false; case '}': if(top>-1 && stack[top--]=='{') break; else return false; default : stack[++top] = *s; break; } s++; } return top==-1; } ``` #### 時間複雜度:O(N), 空間複雜度:O(N) R: 那可以請你用`()[]`解釋一下程式如何運行嗎? ### (Test:) `( )[ ]` E : 跑測資 R: 在switch-case的部分, 針對左括號的操作邏輯看起來一樣的, 那可以請你用if-else將左括號的操作統一處理嗎? ### (Optimization) ```c== bool isValid(char* s) { int len = strlen(s); char stack[len]; int top = -1; while(*s!='\0') { if(*s=='('||*s=='['||*s=='{') { stack[++top] = *s; } else { if(top==-1 || \ (*s==')' && stack[top]!='(') || \ (*s==']' && stack[top]!='[') || \ (*s=='}' && stack[top]!='{')){ return false; } top--; } s++; } return top==-1; } ``` #### 時間複雜度:O(N), 空間複雜度:O(N) R: 恩, if-else的部分也沒有甚麼問題, 感謝您今天的寶貴時間。 ## [9. Palindrome Number](https://leetcode.com/problems/palindrome-number/) R: 你好,我們公司最近在對文本處理和自然語言處理(NLP)中需要做更精確的識別和分類,而其中一項關鍵技術為回文(Palindrome)的檢查,它可以幫助識別一些特定語義或文本的特徵,並應用於判別抄襲或重複內容,甚至是垃圾郵件的檢測。為了簡化測試,為了簡化測試,我們將以整數作為文本內容,請你寫出一個能達到上述效果的函式。 ### (Repeat) E: 所以在這個問題我會先拿到一個整數,那這個整數有可能是正數或是負數吧?而我需要做的事情就是去檢查他是否為一 Palindrome ? R: 沒錯。 ### (Example) E: 舉例來說,假使我今天拿到的數字是 -595 ,那就要回傳 `False` ,而如果是 595 就要回傳 `True` ? R: 是的。 E: 那我的想法會是先去判斷輸入的數是否為正數,如果不是直接 return `False` ,是的話再去做回文的判斷。而判斷的方式為從 `x` 的個位數開始往高位移動,並記錄每一次的值,使得最終得到一個與 `x` 完全相反的數,最後再去判斷兩數是否相等即可。 ### (Code) ```c== bool isPalindrome(int x) { if(x < 0) return 0; int temp = x; int rev = 0; while(temp > 0){ rev = rev*10+temp%10; temp /= 10; } return rev == x; } ``` R: 看起來是可行的,但如果輸入的整數位數比較多,那就會造成 overflow 的情況,你的程式碼有辦法改進嗎? E: 那如果是考量到 overflow 的情形,主要發生的地方會在程式碼中 `rev = rev*10` 的操作,因此我會選擇將 `rev` 的型態從 `int` 改為 `long long` ,如此一來便能使用 64 個位元去儲存。 ```c== int rev; -> long long rev; ``` ### (Test) : 464 R: 你使用了 long long 讓 `rev` 從 32 轉為 64 bits ,這的確可以讓它擁有更大的數值範圍,那如果我希望不使用 `long long` 呢? E: 如果不希望使用 `long long` 且又要避免 overflow 的情況發生的話,那我會選擇用陣列來解決這個問題。首先,將 `x` 的每一位數儲存至陣列裡,然後直接對陣列中相對應的位置判斷是否相等即可,例如有一個大小為 4 的陣列,若他是回文,則 index 0 和 3 的值以及 index 1 和 2 的值必須相等,若有不相等的情況發生則不用繼續比較,直接回傳 `False` 就可以了。 ```c== bool isPalindrome(int x) { if(x < 0) return 0; int temp = x; int count = 0; while(temp){ temp /= 10; count++; } int* arr = (int*)malloc(count*sizeof(int)); for(int i = 0; i < count; i++){ arr[i] = x%10; x /= 10; } for(int j = 0; j < count/2; j++){ if(arr[j] != arr[count-1-j]) return 0; } free(arr); return 1; } ``` R: 謝謝你今天的參與。 ## 初步自評 ### 影片1 : Interviewee * 聲音有點小 * 時常用滑鼠反白做說明, 除非有分享螢幕, 否則Interviewer會看不到 * [2:48](https://youtu.be/8zD7ZNKfKKo?t=168), [5:15 ~ 5:40](https://youtu.be/8zD7ZNKfKKo?t=315)應為`stack[top--]=='('`,stack最上方須對應到`(`左括號, 才能`pop`出,直到[8:03](https://youtu.be/8zD7ZNKfKKo?t=483)才發現錯誤 ### 影片2 : Interviewer * 與Interviewee互動過少, 提出問題後就沒有交流了 * [3:23](https://youtu.be/EohokVYF_Ug?t=203) 問如何避免`overflow`時, 應該用實際遇過的問題包裝來詢問Interviewee如何改進

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully