This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public int countHi(String str) { | |
| if (str.isEmpty()) return 0; | |
| if (str.length()==1)return 0; | |
| return countHi(str.substring(1))+((str.substring(0,2).equals("hi"))?1:0) ; | |
| } | |
| public boolean array220(int[] nums, int index) { | |
| if (index >= nums.length-1) return false; | |
| if (nums.length <= 1) return false; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public int countX(String str) { | |
| return str.isEmpty() ? 0 : countX(str.substring(1, str.length())) + ((str.charAt(0)=='x') ? 1:0); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public int count8(int n) { | |
| int m = n/10; | |
| boolean b = n%10==8; | |
| return n==0 ? 0 : count8(n/10) + (b ? ((b && m%10==8) ? 2 : 1) : 0); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <unordered_set> | |
| struct node | |
| { | |
| node(int data, node* next = nullptr) | |
| : data(data) | |
| , next(next) | |
| { } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* nth node from end */ | |
| void nthNodeFromEnd(node* head, int n) | |
| { | |
| int size = 0; | |
| node* temp = head; | |
| for (; temp; ++size, temp = temp->next) | |
| { } | |
| if (size < n) | |
| return; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<class T> | |
| decltype(f(T())) h() {} | |
| void f(int); | |
| void f(struct X); | |
| struct X {}; | |
| int main() | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <iterator> | |
| class student_fmt; | |
| struct student | |
| { | |
| student() = default; | |
| student(std::string const& name, std::string const& a, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <algorithm> | |
| template<class T> | |
| class dumb_array | |
| { | |
| public: | |
| dumb_array(std::size_t size = 0) noexcept(noexcept(T())) | |
| : m_size(size) | |
| , m_array(size ? new T[m_capacity]() : 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #define LOG_ARG(ARG) \ | |
| do { std::cout << __PRETTY_FUNCTION__ << std::endl; } while (0) | |
| #define LOG LOG_ARG(__PRETTY_FUNCTION__) | |
| class Widget { | |
| class Toolbox { }; | |
| public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <iterator> | |
| #include <algorithm> | |
| #include <initializer_list> | |
| template<typename T> | |
| struct LinkedList; | |
| template<typename T> | |
| struct node |