2023-01-01から1年間の記事一覧
問題 https://leetcode.com/problems/zigzag-conversion/ 答え class Solution { public: string convert(string s, int numRows) { if(numRows == 1) { return s; } vector<string> rows(min(numRows, int(s.size()))); int currentRow = 0; bool goingDown = false</string>…
Problem https://leetcode.com/problems/longest-palindromic-substring/ Answer O(N3) class Solution { private: bool check(string &subString, int subStringSize){ int i = 0; while(i < j) { if(subString[i] != subString[j]) { return false; } i++;…
Problem https://leetcode.com/problems/longest-substring-without-repeating-characters/ Answer class Solution { public: int lengthOfLongestSubstring(std::string s) { std::unordered_map<char, int> map; int maxLength = 0; int left = 0; for (int right = 0</char,>…
Problem https://leetcode.com/problems/add-two-numbers/description/ Answer /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nu…
TypeScriptのRecord型とは? まず、TypeScriptのRecord機能について説明します。 Record型の説明は以下のURLで確認できます: https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type Record型は、2つの型を受け入れることで、あ…
## Problemhttps://leetcode.com/problems/two-sum/description/?envType=featured-list&envId=top-interview-questions ## Answer (Brute Force)```class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { for (int i = 0; i < nums.size() - </int></int>…